0% found this document useful (0 votes)
12 views12 pages

Numerical Methods HW: Armen Hayrapetian

The document is a homework assignment on numerical methods, covering topics such as eigenvalues and eigenvectors, systems of linear equations, and solving equations in one variable. It includes various problems and methods like the Gaussian method, bisection method, Newton's method, and secant method, along with Python code examples for implementation. Each chapter presents specific exercises to apply the discussed numerical techniques.

Uploaded by

maariaam.gh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views12 pages

Numerical Methods HW: Armen Hayrapetian

The document is a homework assignment on numerical methods, covering topics such as eigenvalues and eigenvectors, systems of linear equations, and solving equations in one variable. It includes various problems and methods like the Gaussian method, bisection method, Newton's method, and secant method, along with Python code examples for implementation. Each chapter presents specific exercises to apply the discussed numerical techniques.

Uploaded by

maariaam.gh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

Numerical Methods HW

Armen Hayrapetian

UFAR
2
Contents

1 Eigenvalues and Eigenvectors, Markov Chain 5

2 System of Linear Equations 7

3 Solving equations in one variable 9

3
4 CONTENTS
Chapter 1

Eigenvalues and Eigenvectors,


Markov Chain
 
1 2
1. If A = , then determine the eigenvalues and eigenvectors and find diagonal matrix D
3 −1
such that A = P DP −1 , compute A5 .
 
2 1 0
2. If A = 1 2 0, then determine eigenvalues and eigenvectors.
0 0 3
 
−1 2 0
3. If A =  0 3 4, then determine eigenvalues and eigenvectors and find A12 .
0 0 7
   
0.5 0.7 0.5
4. Let P = be the transition matrix for a Markov chain with two states. Let x0 =
0.5 0.3 0.5
the initial state vector.
(a) Compute x1 , x2 .
(b) Compute xn .
(c) Find the steady state vector.
 
0.3 0 0.2
5. Let P = 0.3 0.5 0.3 be the transition matrix for a Markov chain with the initial state
0.4
 0.5  0.5
120
vector x0 = 100 .
120
(a) Compute x1 , x2 .
(b) Find the steady state vector.
0 13 13
 

6. Let P =  12 0 23  be the transition matrix for a Markov chain with the initial state vector
1 2
0
  2 3
1
x0 = 0 .
0
(a) Compute x1 , x2 .
(b) Find the steady state vector.

5
6 CHAPTER 1. EIGENVALUES AND EIGENVECTORS, MARKOV CHAIN
Chapter 2

System of Linear Equations

1. Consider the system of linear equations, solve the system by using the Gaussian method to
write it as RREF(reduced row echelon form).

 x1 + 2x2 + 3x3 = 4
2x1 + x2 + x3 = 3 (2.1)
4x1 + 2x2 + 4x3 = 8



 2x1 + x2 − 3x3 + 4x4 = 8
3x1 + 2x2 + x3 − 2x4 = 1

(2.2)

 4x1 + x2 − 5x3 + x4 = 4
3x1 + 2x2 − 4x4 = −4

2. First write the system to the useful form for iteration and solve it by using Gauss-Jordan
iteration method and the given initial solution.
  

 2x1 + x2 − 3x3 − 4x4 = 8 0
3x1 + 2x2 + x3 = 1 0

, x0 =   (2.3)

 4x1 + 2x2 + 2x3 − x4 = 2 0
2x1 + x2 + 3x3 + 2x4 = −4 0

3. First write the system to the useful form for iteration and solve it by using Gauss-Seidel
iteration method and the given initial solution.
  

 2x1 + x2 − 4x3 − 2x4 = −10 −0.5
3x1 + 2x2 − x3 + x4 = 3  1.5 

, x0 =   (2.4)

 x 1 + 3x 2 + 2x 3 − x 4 = 4  0.5 
3x1 + 3x2 − 2x4 = −3 3.2

7
8 CHAPTER 2. SYSTEM OF LINEAR EQUATIONS
Chapter 3

Solving equations in one variable

Bisection Method
Use bisection method to find solutions, accurate to within 10−5 for the following equations.
1. x + 1 − 2 sin(πx) = 0, x ∈ [0.5, 1], x ∈ [0, 0.5]
2. ex − 2(x − 2)2 = 0

3. ex − 3x2 = 0, x ∈ [0, 1], x ∈ [3, 5]


The python code for the bisection method.
Here is the solution for
x3 − 2x2 − 5 = 0, x ∈ [2, 3]

import numpy a s np
import math

def f (x ) :
r e t u r n x ∗∗3 + 2∗ x ∗∗2 −5

def B i s e c t i o n ( f , a , b , t o l = 10∗∗( −5)):


i f np . s i g n ( f ( a ) ) == np . s i g n ( f ( b ) ) :
p r i n t ( ” Change a o r b v a l u e . ” )

e l i f np . s i g n ( f ( a ) ) != np . s i g n ( f ( b ) ) :
p r i n t ( ” f has a t l e a s t one r o o t i n [ a , b ] . ” )
m = ( a + b)/2
p r i n t (m)
i f np . abs ( f (m) ) < t o l :
# Stopping condition , r e p o r t m as root
p r i n t (m)
e l i f np . s i g n ( f ( a ) ) == np . s i g n ( f (m) ) :
# Make r e c u r s i v e c a l l with a = m
r e t u r n B i s e c t i o n ( f , m, b , t o l )
e l i f np . s i g n ( f ( b ) ) == np . s i g n ( f (m) ) :
# Make r e c u r s i v e c a l l with b = m
r e t u r n B i s e c t i o n ( f , a , m, t o l )

Bisection ( f ,2 ,3)

9
10 CHAPTER 3. SOLVING EQUATIONS IN ONE VARIABLE

Newton Tangent Line Method

f (xn )
xn+1 = xn −
f ′ (xn )

Use Newton’s method to find solutions, accurate to within 10−5 for the following equations.
1. ex − 3x2 = 0, x ∈ [0, 1], x ∈ [3, 5]
2. ex − 2(x − 2)2 = 0

3. (x − 2)2 − ln x = 0, x ∈ [1, 2], x ∈ [2.7, 4]


The python code for the Newton’s method.
Here is the solution for
x3 + 2x − 1 = 0, x ∈ [0, 2]

def f (x ) :
r e t u r n x∗∗3+2∗x−1
d e f Df ( x ) :
return 3∗( x ∗∗2) + 2
d e f Newton ( p ) :
N = p − f ( p ) / Df ( p )
i f f (N) < 0 . 0 0 0 0 1 and f (N) > −0.00001:
return N
else :
p r i n t ( ’ ˜ r o o t = ’ ,N , ’ f ( ˜ r o o t )= ’ , f (N) )
Newton (N)

Newton ( 1 )
11

Secant Method
f (xn )(xn − a)
xn+1 = xn −
f (xn ) − f (a)
Use Secant’s method to find solutions, accurate to within 10−5 for the following equations.
1. ex − 3x2 − 2 = 0
2. ln x − 2x − 8 = 0

3. (x − 2)2 − ln x = 0, x ∈ [1, 2], x ∈ [2.7, 4]


The python code for the secant method.

import math

def f (x ) :
r e t u r n x ∗∗3+3∗( x ∗ ∗ 2 ) −1
d e f s e c a n t m e t h o d ( f , x0 , x1 , t o l =1e −5, n =0):
n += 1

y0 , y1 = f ( x0 ) , f ( x1 )
# c a l c u l a t e fu nctio n values at endpoints

xn = x1 − y1 ∗ ( ( x1 − x0 ) / ( y1 − y0 ) )
# c a l c u l a t e next r o o t a p p r o x i m a t i o n
p r i n t ( f ’ n={n} xn={xn } ’ )

i f −t o l < y1 and y1 < t o l :

r e t u r n xn , n
# check t o l e r a n c e c o n d i t i o n

r e t u r n s e c a n t m e t h o d ( f , x1 , xn , n=n )
# r e c u r s i v e c a l l with updated i n t e r v a l

s e c a n t m e t h o d ( f , −3, −2)
# C a l l f u n c t i o n and run .
12 CHAPTER 3. SOLVING EQUATIONS IN ONE VARIABLE

Combined Method, Newton Tangent Line and Secant Methods

• If f ′ · f ′′ > 0, the {bn } is given by Newton’s method and {an } is given by secant method.

f (b)
b1 = b −
f ′ (b)

f (a)
a1 = a − (b − a)
f (b) − f (a)
So
f (bn )
bn+1 = bn −
f ′ (bn )
f (an )
an+1 = an − (bn − an )
f (bn ) − f (an )

• If f ′ · f ′′ < 0, the {an } is given by Newton’s method and {bn } is given by secant method.
• Let
an + bn
pn =
2
then the sequence {pn } tends to the root.

Find the roots of the given equations by using combined method.


1. x2 log(x + 1) − 2 = 0

2. ln x − 2x − 8 = 0

You might also like