Microprocessor Notes
Microprocessor Notes
NON-LINEAR EQUATIONS
1. Bisection method
4. Secant method.
Bisection method
1. Show that f ( x )=x 3 + 4 x 2−10 has a root in [1, 2], and use the Bisection method
Solution:
Here [ a , b ]= [ 1 , 2 ]
When we have a shift from negative to positive, we say that the root lies between those values
Bisection method:
a+ b 1+2
p1 = = =1.5
2 2
a+ p1 1+1.5
p2 = = =1.25
2 2
p2 + p1 1.25+1.5
p3 = = =1.375
2 2
p4 =1.3125
Iteration an bn a n + bn f ( pn)
pn =
2
1 1 2 1.5 2.375
2 1 1.5 1.25 −1.796875
3 1.25 1.5 1.375 0.16211
4 1.25 1.375 1.3125 −0.84839
5
6
7
8
9
10
11
12 1.3648 1.3653 1.3651 −0.00297
13 1.3651 1.3653 1.3652 −0.0005
14 1.3652 1.3653 1.36525 0.00033
Given interval: [ a , b ]
Iterative formula:
af ( b )−bf ( a )
p1 =
f ( b ) −f ( a )
Solution:
x−cos x =0
f ( 0 )=0−cos 0=−1
f ( 1 ) =1−cos 1=0.4597=+ve
Iterative formula:
f ( p 1) =¿ mid value ¿ ¿ ¿
Note:
Example 1.8
3
f ( x )=x −4 x +1
f (x n )
x n+1=x n −
f ' (x n )
Here f ( 0 )=−ve ; f ( 1 ) =+ ve
Assume x 0=0.5
f (x 0) f (0.5) 0.625
x 1=x 0− =0.5− =0.5− =0.3333
f ' (x 0) f '(0.5) 3.75
'
where , f ( 0.5 )=0.625 ; f ( 0.5 ) =3.75
To find x 2
f (x 1 ) f ( x 1)
x 2=x 1− =0.3333− =0.3222
f '(x 1 ) f ' (x 1)
f (x 2 ) f ( x2 )
x 3=x 2− =0.3222− =0.3222
f '( x2 ) f ' (x 2)
n x0 f (x n ) f ( x n +1 ) f ' ( x n +1 )
x n+1=x n −
f ' (x n )
0 0.5 0.3333
1 0.3333 0.3222
2 0.3222 0.3222
Secant Method
Hint:
Given: Interval [ f 0 , f 1 ]
x + y + z=1(1)
x− y +3 z=0 (2)
x−2 y +3 z=0 ( 3 )
x +3 z=0(5)
−1
equation ( 4 )−2equation ( 5 )−2 z =1 z=
2
Sub z in ( 5 ) ,
3
x− =0
2
3
x=
2
Substitute in (1)
x + y + z=1 ( 1 )
3 1 3−1
+ y− =1 ⇒ + y=1 ⇒ 1+ y =1⇒ y=0
2 2 2
Solution:
3 −1
x= ; y =0 ; z=
2 2
1. Direct Methods
2. Indirect/Iterative Methods
Note:
Direct Methods: Gauss- Elimination method, Gauss Jordan method, Matrix Inversion method
etc
Iterative Methods: Gauss Seidel method, LU Decomposition method
Procedure:
Hint:
[ ]
a 11 a12 a 13
A= a 21 a22 a 23
a 31 a32 a 33
Below the diagonal elements, make all entries zero....this is called Upper Triangular matrix
[ ]
a11 a12 a13
0 a22 a23
0 0 a33
Above the diagonal elements, make all entries zero....this is called Lower Triangular matrix
[ ]
a11 0 0
a21 a22 0
a31 a32 a33
Problem 1:
Solution:
Step 1:
A=
[ 11 −21 ] ; X=[ xy ] , b=[−12]
Augmented ¿ [ A∨B ]=
[ 11 −2
1 −1
2]
R2 → R2 −R 1
[0
[ A∨B ]= 1 1 −1
−3 3 ]
Let us check how the system of equations looks like:
x + y=−1
−3 y=3
Back substitution:
−3 y=3 ⇒ y=−1 ;
x + y + z=1(1)
x− y +3 z=0 (2)
x−2 y +3 z=0 ( 3 )
Solution:
Step 1:
Matrix form:
[ ] [] []
1 1 1 x 1
A= 1 −1 3 , X = y B= 0
1 −2 3 z 0
Augmented Matrix:
[ ]
1 1 1 1
[ A :B ] = 1 −1 3 0
1 −2 3 0
Step 2:
Hint:
R2 → R2 −R 1 ; R3 → R 3−R1
[ ]
1 1 1 1
[ A :B ] = 0 −2 2 −1
0 −3 2 −1
[ ]
1 1 1 1
[ A :B ] = 0 −2 2 −1
0 0 10 −5
x + y + z=1
−2 y +2 z =−1
10 z=−5
Back Substitution:
−5 −1 −1
10 z=−5 ⇒ z= = ⇒ z=
10 2 2
Substitute in −2 y +2 z =−1
1 1 1
⇒ x +1− =1 ⇒ x+ =1 ⇒ x=
2 2 2
Procedure:
Hint:
Diagonal matrix
[ ]
a11 0 0
0 a22 0
0 0 a33
Problem 3: Solve the following system of equations using Gauss Jordan method:
x + y + z=1(1)
x− y +3 z=0 (2)
x−2 y +3 z=0 ( 3 )
Solution:
Step 1:
Matrix form:
AX=B
[ ] [] []
1 1 1 x 1
A= 1 −1 3 , X = y B= 0
1 −2 3 z 0
Augmented Matrix:
[ ]
1 1 1 1
[ A :B ] = 1 −1 3 0
1 −2 3 0
Step 2: Using elementary row operations, we reduce the above matrix into diagonal matrix...
[ ]
2 0 0 1
[ A :B ] = 0 1 0 1
0 0 2 −1
2 x=1
y=1
2 z=−1
[]
1
2
X= 1
−1
2
Matrix Inversion Method:
AX=B
To find X =? ? ? ?
( A−1 A ) X= A−1 B
−1
IX =A B
−1
X =A B
Where
−1 1
A = adj (A )
| A|
Example:
x− y =3
x +2 y=6
Solution:
A=
[ 11 −12 ] , X =[ xy ] , B=[ 36]
Solution set is given by: X =A −1 B
|1 2 |
| A|= 1 −1 = (1 )( 2 )− (1 )(−1 )=2+ 1=3 ≠ 0
Hint: If | A|=0 implies A is a singular ¿ Therefore ,inverse does not exist for A .
−1 1
A = adj ( A )
| A|
−1
A =
[
1 2 1
3 −1 1 ]
3 [−1 1 ][ 6 ] [−1/3 1/3 ][ 6 ]
−1 1 2 1 3 2/3 1/3 3
Solution set, X =A B= =
¿
[−12 /3/3×3+ 1/3× 6
]
×3+ 1/3× 6 −1+2
=
[ 2+2
] =
[ 1]
4
X=
[ 41]
Gauss – Seidel Method (Iterative Method)
|a11|>|a12|+|a 13|
|a22|>|a21|+|a23|
|a33|>|a 31|+|a32|
Example:
[ ]
10 −2 4
A= 2 −8 3
−4 2 9
Example:
[ ]
2 −8 3
A= 10 −2 4 This matrix is not diagonally dominant. Therefore, we interchange first and the
−4 2 9
second rows...to make it as a diagonally dominant matrix.
Step 5: When we get same values in the following iterations, we truncate the iteration and get the
solution set.
Problem 1
Solve the following system of equations by applying Gauss Seidel method:
Solution:
[ ] [] [ ]
2 10 1 x 13
A= 10 2 1 ; X = y ; b= 13
2 1 10 z 13
Given matrix is not diagonally dominate, so we interchange 1st and 2nd row
[ ] [] [ ]
10 2 1 x 13
A= 2 10 1 ; X = y ; b= 13
2 1 10 z 13
1
10 x+ 2 y + z=13 ⇒ 10 x=13−2 y−z ⇒ x= [ 13−2 y−z ]
10
1
2 x+10 y + z=13 ⇒ 10 y =13−2 x−z ⇒ y= [ 13−2 x−z ]
10
1
2 x+ y+10 z=13 ⇒ 10 z=13−2 x− y ⇒ z= [ 13−2 x− y ]
10
1
x (1 )= [ 13−2 y (0 )−z (0 ) ]= 1 [ 13−2 ( 0 )−( 0 ) ]= 13 =1.3
10 10 10
1
y (1 )= [ 13−2 x (1) −z (0) ]= 1 [13−2 ( 1.3 )−0 ]=1.04
10 10
1
(1)
z = [ 13−2 x (1)− y (1) ]= 1 [ 13−2 (1.3 )−1.04 ]=0.936
10 10
[ ][ ]
x (1 ) 1.3
New values are: y (1 ) = 1.04
( 1)
z 0.936
Iteration 2:
1
x (2 )= [ 13−2 y (1 )−z (1) ]= 1 [13−2 ( 1.04 )− ( 0.936 ) ]=0.9984
10 10
1
y (2 )= [ 13−2 x (2) −z (1) ]= 1 [ 13−2 ( 0.9984 ) −0.936 ]= 1.00672
10 10
1
(2)
z = [ 13−2 x (2)− y (2) ]= 1 [13−2 ( 0.9984 ) −1.00672 ]=0.9996
10 10
[ ][ ]
x (2 ) 0.9984
New values are: y (2 ) = 1.00672
( 2)
z 0.9996
This problem goes till 5th iteration, and then the values gets repeated...therefore we stop iterating
further.
[ ][ ][]
x (5 ) x (6 ) 1
y ( 5 ) = y ( 6) = 1
( 5) ( 6)
z z 1
Note:
When the two set of iterations remain the same, we can terminate the procedure.
LU Decomposition Method:
A=LU
Where
[ ] [ ]
1 0 0 U 11 U 12 U 13
L= L21 1 0 ∧U = 0 U 22 U 23
L31 L32 1 0 0 U 33
2. Take Y =UX ⇒ LY =B. Using Forward Substitution, we solve this system to get the solution of Y
.
3. Atlast, Using Backward Substitution solve for UX =Y . Here we get the solution for X .
Unit 2
Numerical Differentiation
'
f ( x 0 +h ) −f ( x 0 ) f ( x 0 +h ) −f ( x 0 )
f ( x 0 )=lim =lim
h→0 x 0 +h−x 0 h →0 h
Where x 0 +h= x1
x 0−2 h x 0−h x0 x 0 +h x 0 +2 h
2 3
h ' h '' h ' ''
f ( x 0 +h )=f ( x 0 )+ f ( x0 ) + f ( x 0 ) + f ( x 0 )+ …
1! 2! 3!
2 3
h ' h '' h ' ''
f ( x 0 −h ) =f ( x 0 )− f ( x 0 ) + f ( x 0 )− f ( x 0 ) +…
1! 2! 3!
'
f ( x0 + h )−f ( x 0 ) h ''
f ( x 0 )= − f (ξ )
h 2
'
f ( x0 ) −f ( x 0 −h ) h ''
f ( x 0 )= − f (ξ )
h 2
'
f ( x0 + h )−f ( x 0−h ) 2
h ' ''
f ( x 0 )= − f (ξ )
2h 6
Note:
Extrapolation
(10 marks)
N j ( h )=N j −1 () h
2
+ [ N j−1 ( h2 )−N
4 j −1−1
j−1 ( h)
]
Numerical Integration
Definite integrals:
b
∫ f ( x ) dx=F ( b ) −F (a)
a
x x0 x1 x2 x3 x4
y=f (x ) y0 y1 y2 y3 y4
Trapezoidal rule
b xn 3
h h h ''
∫ f ( x ) dx=∫ f ( x ) dx = 2
[ ∑ of first∧last ordinate ] = [ y 0 + y n ]− f ( ξ )
2 12
a x0
b−a
where x 0 <ξ < x n and h=
n
b−a
Where h=
n
b xn
h h
∫ f ( x ) dx=∫ f ( x ) dx = 3 [ ∑ of first∧last ordinate+ 4 ( remaining ordinates ) ]= 3 [ y 0+ y n+ 4 ( y1 + y 2 + y 3 +…+ y n
a x0
b−a
where x 0 <ξ < x n and h=
n
b xn
h h
∫ f ( x ) dx=∫ f ( x ) dx = 3 [ ∑ of first∧last ordinate+ 4 (∑ of odd ordinates )+2 (∑ of even ordinates ) ]= 3 ¿
a x0
b−a
where x 0 <ξ < x n and h=
n
−2
taking n=4 and verify by actual integration.
Solution:
b−a 2−(−2 )
length∨space width ,h= = =1
n 4
x x0 x1 x2 x3 x4
y=f (x ) y0 y1 y2 y3 y4
x −2 −1 0 1 2
3 −2
f (−2 )=(−2 ) e =−1.0826
3 −1
f (−1 )=(−1 ) e =0.3678
f ( 0 )=0
3 1
f ( 1 ) =( 1 ) e =2.718
3 2
f ( 2 )=( 2 ) e =59.112
b x4
h h 1
∫ f ( x ) dx=∫ f ( x ) dx = 2 [ ∑ of first∧last ordinate+2 ( remaining ordinates ) ]= 2 [ y 0+ y 4 +2 ( y 1 + y 2+ y 3 ) ]= 2 [−1
a x0
b x4
h 1
∫ f ( x ) dx=∫ f ( x ) dx = 3 [ y 0 + y 4 + 4 ( y 1 + y 3 ) +2 ( y 2 ) ]= 3 [−1.0826+59.112+ 4 ( 0.3678+ 2.718 ) +2 ( 0 ) ]=23.457
a x0
'
Bernoulli s rule isthe extension of Integration by parts
where Integration by parts=∫ udv=uv−∫ vdu
∫ x 3 e x dx=? ? ? ?
−2
Hint: The variable which vanishes can be taken as u... and the remaining can be dv
3 x
u=x , dv=e dx
u =3 x , v=∫ e dx=e
' 2 x x
u =6 x , v 1=∫ e dx=e
'' x x
u =6 , v 2=∫ e dx=e
' '' x x
2
2 2
∫ udv =∫ x 3 e x dx=uv −u' v 1+u '' v 2−u' ' ' v3 + …=[ x 3 e x −3 x 2 e x +6 x e x −6 e x ]−2 ={e x [ x 3−3 x2 +6 x−6 ] }−2={e 2 [ 8−
−2
Conclusion:
Differential equation:
dy
=f ( x , y )
dx
Differential equation along with the initial conditions are called IVP (Initial value problem) (2 marks)
Given a table:
x x0 x1 x2 x3 x4
y=f (x ) y0 y1 y2 ? ?
(i) Find y 3 Euler’s method (ii) Find y 4 Corrector method.
Methods:
1. Euler’s method
Euler’s method
Iterative formula:
1
k= [ k + 2 ( k 2+ k 3 ) + k 4 ]
6 1
y i+ 1= y i+ k
Solve the IVP (Initial value problem): y ' =t + y ,0 ≤ t ≤ 0.2 , y ( 0 )=1 with h=0.1
Solution:
Given:
'
y =t + y ,0 ≤ t ≤ 0.2 , y ( 0 )=1 with h=0.1
( t 0 , y 0) = ( 0 , 1 )
1. Euler’s method
To find y 1:
Iterative formula:
Given: f ( t , y )=t+ y
To find y 1:
y 1=1.1
Answer: ( t 1 , y 1 )= ( 0.1 ,1.1 )
To find y 2:
Put i=1
2 3
h ' h '' h ' ''
y 2= y 1 + y 1 + y 1 + y 1 +…
1! 2! 3!
( t 1 , y 1 )= ( 0.1 ,1.1 )
' '
Given: y =t + y y =0.1+1.1=1.2
'' ' ''
y =1+ y y =1+1.2=2.2
' '' '' ' ''
y =y y =2.2
(4) '' ' (4)
y =y y =2.2
2 3 4
0.1
y 2=1.1+ ( 1.2 ) + 0.1 ( 2.2 ) + 0.1 ( 2.2 ) + 0.1 ( 2.2 ) + …
1! 2! 3! 4!
( t 2 , y 2 ) =( 0.2 ,1.231 )
Answer:
Problem 2:
Solve the IVP (Initial value problem): y ' =t + y ,0 ≤ t ≤ 0.4 , y ( 0 )=1 with h=0.1
1
k= [ k + 2 ( k 2+ k 3 ) + k 4 ]
6 1
To find y 3:
Given: f ( t , y )=t+ y
( h k
)
k 2=hf t 2 + , y 2+ 1 =0.1 f ( 0.2+0.05 ,1.231+0.0715 )=0.1 f ( 0.25 , 1.3025 )=0.15525
2 2
( h k2
)
k 3=hf t 2 + , y 2 + =0.1 f ( 0.2+ 0.05 ,1.231+0.0077 )=0.1 f ( 0.25 , 1.2387 )=0.14887
2 2
1 1
k=
6
[ k 1+ 2 ( k 2+ k 3 ) + k 4 ] = [ 0.1431+2 ( 0.15525+0.14887 )+ 0.16798 ] =0.15322
6
y i+ 1= y i+ k
( t 3 , y 3 ) =( 0.3 , 1.38422 )
Predictor- corrector method:
To find y 4 :
4h
y4= y0+
3
[ 2 f ( t 1 , y 1 )−f ( t 2 , y 2 ) +2 f ( t 3 , y 3 ) ]
We know from table:
Therefore,
4 ( 0.1 )
y 4 =1+
3
[2 f ( 0.1, 1.1 )−f ( 0.2 ,1.231 ) +2 f ( 0.3 ,1.38422 ) ]
We get,
h
y 4 ,c = y 2 +
3
[ f ( t 4 , y 4 , p ) + 4 f ( t3 , y 3 )+ f ( t 2 , y 2 ) ]
Therefore,
y 4 ,c =1.5688
Complete answer is