0% found this document useful (0 votes)
36 views

Numerical Methods and Programming

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)
36 views

Numerical Methods and Programming

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/ 197

PHY 312 Relative

300ke
I
-- grading
=> Numerical methods - S C
.
..

Chapra

=>
Applied Numerical
Analysis
-
Gerald &
Wheatley
Tap
=> Intro to
Comp .

Physies >
-
Pang
Evaluation
-

End Sem >


- 50 % (Thory + Practical)

Mid San > 25 %


/mory)
Quiz (2) - 25
% (Practical)
Content

① Roots of Equation

② Linear Algebraic Equations


> Regression
-
③ Curve
fitting Le Interpolation
④ Integration
⑤ O D E
.
.

⑥ P.
D E .


V

ma =

= #
o
ma
C
mg
= =

=g- - - - -

-

de gmo
=

M
mg/c
0
v= 0
It

=
=
+
at -

co
=
cit

It

=
e

= get

=" gat

: 7 get
=
K

-
8
1 -

-
cgt
1 e
gi
k
Eve
=
-

5
WH
=

g (1
-
!
S + Ko

=
at +
v
=

=
0

0
ge
so K = 0

(1 =
)
O

v c
g
=
>
-

-
= limit A

)
=v(ti) g - (ti
-

tit-ti

r(ti + ) =
~(i) +

<g -

(i) J(it -

+)

Errors
-

Kinds
of errors
Error data
=> in the
original
=> Human error

=> Truncation error


ex -
.

=>
Propogation error

=> Round off error


significant
digits
I
dentifySig digits .
:-

0 .
001845 - 4 4 .
63 x 104 >
- 3

0001845 104
0 .
-
y 4 630
.
x - Y

0 01845 - y 104 >


- 5
4 6300 x
.

2 5 . x 3 42
. = 8 550 .

3 0800
.
=
7 .
08 x 100

= 8 .
6
=> 3

22 .
101 - 0 .

9307

I 21 .
1703

=
21 : 17

Precision
Auracy
&
Pres
>
+

: O

: E
Al E
~
Representation
of no

=>
Floating point representation
=>
Integer representation
-
mantissa
C
~
exponent
X =
I(.d , dcds ...

dp) B = I
mpe
↳ ↓
martia
base
p- significant digits
>

64 Sits

I lit >
-
sign of the no . - 0 = + ve

1 =- ve

II lits >
exponents lit forsinthefor exponent
(21 =
1024)
52 lits-mantissa
Normalization
of Mantisa

sig digits
->
Y .

34

= 0 .
0294/ ....

= 0 .
0294

to exponent
2941
shifting
=
0 .
>
-
O

1 m < 1

B
-

L ↓
bas mantissa

for love 10 0 . 1 < m < I

(hypothetical
it s machine)
magnitude of

signexponent exponent

11 / I I I
L -
of to magnitude of
exponent
sign i
mantessa
-
called
Smallest + ve no /len than this is

underflow error)

0(1/2(2/110/0 =
2

Besausebas

O
>
-
B
=

2-3 this ?? +S
+ 0 . 5 x
Why 0
.

0625 B

3
= 0 asses
O
.

Next 0 .
078/25

(x)
= II
vo
O
-
- 0 .

09375 14

- 109375
0
1/
↓ machine

I IS
Whats efisdon
O -
IC5000
IX, thi ! IX/

It previous
is

more than
above value
O .
156CSO

IIIIIIIII - I
7
I
is
there
0625 which
0
7 (beyond
Bot
.

>
-
error)
overflow

0
101 1 :
III / ,
lits

Highest no .
>
-
32767

Lowest no .
- -

32760

Machine
Epsilon

1 E

E in

of sig
.
digits
I-XXno
.

mantessa
Es

=

base
Representation
of numbers

=> Underflow error

=> Over
flow error

-
-
Machine efiiton

=>
Integer representation

Normalized
floating point representation
=>

We will the to
move
exponent
& T S

value topreserve scientific


higher &
A notation .

lose
As
some
a result
digits
we
will

=>
0 00 US E7
0 4546 E S
.

0 543 &T 0 S43) G7


=
.

S478
E 7
-
x
6
= u = 3 s

Laws of distribution , associativity will not

be
exactly followed.

0 .
5 86 .

-chopping
>
- U -
S56LO

rounding >
-
0 .
55679

off

6x f X + x + x + x + x + x

c(a- b) + a) -

ba

concept of Zero
- floating point
0
Xt -

2x 2 =

roots >
- 1 3

= 0 .
7320 E O

-
0 .
2732 E I
=

(x +
+ 2x) -
2 = - 0 .
100t -
2

x +
(2x 2) =
0 .
2007 -
3)

e-x = 1 -
x + L
&
2
-
x + . .

2
! 3!

let x =
5 5
.

Catastrophic Cancellation
When two
very large numbers
>
- are
the doesn't
subtracted ,
round
off error
give
small number
.
very
x
1
-

e =

ex

* substractions can be a
problem .

* Optimisation is
important :

Wher should we
stop ?

Error
Error
= Trus value -

Approximation

Fractional
error-Trevue affrox .

X 10 e
Ex
true error a
=
x 10
-

L
fractionalerror
T

true ...
C

desalve
- approach
Ca
froximate e
-
o
x

eroe
=


fractional
approximate
error

E A
=
curren
approx Previous approx
.
-
.

100%

current approx.

Es -acceptable value
of error

(0 102
-

7) /
Es
%

=
.
5 x
J
Scarborough
significant digits ,

n -
1966

Ital < Es then truncate
propogation
Error

f(x) => x =>


L


f(x)
x -
x =
>
f(x) -

f(x)

Af(x)
=

(f(x) -

f(x))

* -> close to X

Taylor
about
series
expansion of f(x)


differentiable
-

continuous and

O
~

f(x) =
f(x) +
85) -
+

8 21
+
*

- - -

x)
=> f(x) -

f(x) =
f(x)(x -

A
f(x) =

(8()((x x) -
↓ A f(x) 18(7)((x /
=
-

sharp function
-
careful

N org Lots ...


x X

f(Un , ) f(ui (i)


=

,
+
16 1. it is

Vil
+
Vi -

[ us (Uit
·
2
+
-

Wil
,

↑ Wit -

Vis
- +

(n Sitt-uis(in

t -

. . .
-vi))

& (Ui +, Vit) f(Ui vi)


+ /Mix-Mis
=

I wi (Wit-vis

-
f(, ) 1/ 10
= +

Patility
condition
and :-

sensitivity to value
growth of change in
input
errors/uncertainty
sensitivea
o

if
fri very
a
>
- ill-condition

function
-

I make it toa
well condition

fu

computation is
growing - unstable
function
uncerlundly
---
the

Condition
number

Relative error in
f(x)
=

8 f(y)
f(x)
= i
x
Relative error in X
=
*
*

R error in
f(x)
Condition )
.

no = -
-

in
.

Berror
(CN) f(5)

condition
Higher no .
-
Higher sensitivity
Or

Magnification of
error

Relative
CN > 1 -
error is
magnified

bad

IN < 1 - Relative error is


suppressed

good
f(x) XX
example
=

<N

1 x
=
=

*
E
=

nu-a'v
-
f(x) , O
=

ex =
UL
1 - xV
-
(2x)10
x rp
=
-

(1 -

1=
(N =

=
20X
Ill conditioned near X =
1

Well-conditioned near X = 0

large x -> ill-conditioned

f(x)
=

2/f + -

xx)

(n
1=
=

I
= I
El
·
·
X
L
= 12682 - CN =

(Runge)
for X-large
true value well conditioned
>
-

> computed
-
o difference
value
(using float)

* Even if (N =
E ,
as
float has less lite , for

Because
large X ; we will
get errors .
we

are
subtracting two
large numbers
/very close

to each other
2/ -XX)) will
give
errors
.
We can rationalize in this case
;

f(x) 2/ + +
x)
/
= -

-
2

#x 1 +

ex
f(x) at X
=
= 12

1 at
f(x) X 12
=
=

e-X

Find the
Taylor series
?

S1 : 1 + X
Find CN at

-2 :
X .
X different steps ?

-3
:
/2
Roots
of Equations

f(x ,
y ,
.... ) = 0

f(x) = 0

Plot the
function
M

&
n ↑ & 00 ⑥
>

S1 :

Graphical Method
T
-2 :

ce

X
raming "
I

Oppositi
signs

!
I

⑳ ⑧-

I I

I
I
&

!
I

I
-

Ye Ye
Fes It
not
o
sign>O even

EL
name Y -
-

opposite sign-odd no ·

of roots

Choose initial
the value
correctly
.

Bracketing Method -
>
- Xu
Xe ,

>
- It will converge

to the root
>
-
Open method >
- X;

>
-
guarantee
will not

to the root
convergence
but can be
faster at

times
Bracketing Methods

(i) Direction
method

No x A

-1 : Choose Xe and Xu

st .

f(xe) f(x) < O

: Y = x
If f(xe) f(x) < 0 =>> Xu Ye
:
=

If f(xe) f(xe) >0 = Xe =


Xe

f(x e) f(x) STOP


-
=
0

>
- Most time
the
of
we will not
get
Ea =
I -Xe I
I
x 100 %
.
here

we
which
Tolerance
When Ea < Es- decided

=> STOP there

Xe-root
=>
of function
(ii)
d
Method/Fals position
Linear interpolation
method
-

1 Xu

f(xu]
Xr
C C
#-
O

f(x)
E
de
e
~

Xe
f(xn) Xef(xu)
-

f(x1) Xm- Unf(x)

Ya = x
f(x)) -

xef(xu)

b(x2) -

f(xn)

=> Function called


4 times
xn = Xu -

f(xu)(Xe
xn] -

b(x e) -

f(Xu)

3 times
Function called
.

=>

Error
analysis
Bisection Method in

o O

X,
Zeroth
iteration
S
Xu

Ax =
Xi -
Xi = Ea

Ea'
D
=

2
Ea
=
[

Ea" =

17
2
Ead - desid error

Ead
a
=

= n =

en(1xyE

Open
methods

(s Newton
Raphson-


f(xi) = = = stope
Xi -

Xi + /

His
Xin = xi
-

j'(xi)
=

second method
Root
Methods
finding
Bracketing
-

>
-
Open
xr
x
=

Bisection
3

↑ & Xu

② False
position xr =
Xu - -
Xul

f(x) f(xn)
-

xe 0
x -
=

1
f(x)
-

-
> Xu 1 3
= .

f(x)

~"s
a

-X↑
⑧ -

+
I
--
V

-
x =
roan
=

0
is
= 0 . 094

is 0 975
.
O -
172

0 . 094 -

/1 . 3 -0 .
097)

17 78 + 1
.

=
0 094
20 o
.
+

= 0.094 + 0 .

0815

=
0 . 1719

Newton-Raphson

y
xi + 1
=
xi =

f(x)
is

:
f(xi +
1) =

f(xi) +
f(xi)(Xi +
-
Xi)

that
-
O

Cou assumption
nex
t
is
-
I
In
+ 2 !
-

OI

terab on
-

7
roof

Xi + 1 =
Ye

0 =

f(xi) +
f(xi)(x - xi) +

1) A x
-

↳ t ---

Subtracting 20:-

0
j(xi)(x1 1)
f x) (x
xi
=

-Xi
-

+ +

/ ,
↓ ↓
Ex i
Et ,
it
,

fi
Et =.
,
i ,
in
S

I
I

&

Fan e

=>
Inflection Joint

f"(x) = 0
&

!
-

·
points
Xi

are
)

+ 2

diverging
or
min
Rocal

t
M

maxima

&
S

V
maximal

·
near

2 --
,
it
e
-

divage S

root
away from

* Keep a check on whether


J(xi) is

close to Zero or not.

Multiple
roots

f(x) =
( -

x 1) Q(x)

> I & even


M

multiple
even
roots

V >

In these
types of functions
d
f(X) will reach zero

Jod
faster than J//vi)

moment

f(x) = 0
u(x y) ,
= 0

v(x ,
y) = 0

f(x) =
f(xi + 1)
=

f(xi) +
f[xi) (xit -

O
III

H(Xi Yi 1) k(xi Yi)


=
+ 1 +
, ,

+ /Xi yi) < (Xi +


-

X
)
7 U: JY
yi) = U(xi ,

+
(xi yi), (yi +
-

yi)
O
III
v (i + 1
, Yi 1)
+
= 0: +

(ii) I ;

+
(yi +
-

yi) /;
Xi + Xi hi
/i V
;
=
1
-
-

i
-

↓ li lili

it yi
1
+ ki
=

:
-

* 1, 1 li
-
li

-
Poisson's bracket

Or

Jacobian the
of system
Roots
of polynomial

Bairstow
method

x4 x" 3x3
f(x) +
=
-

+ x + 2

lets assume x = 4

divide
by -4) , get the
quotient.

nt
f(x) = 0 order

Assume This
-

x2 -

rx - S
-
-

is a
factor
Linear
Algebrais Equ
Felt
10

f(x) , xz , . xn) =
0

fz(x1 ,
xz
,
. -
x n) = 0

f(x1 , x2 ...
(n) = 0

In(x1 ,
X2
,
. ·
X n) = 0

linear
I's -

91 , x1 + 912x2 + b)
anyn
=
-
- -

921X1 + 9222 + ... - + 92nXn =


b2

'
S

anix, + anax2 +.. - -


Amxn = bu
[A] Ex 3 =
[B]

Ex 3 =
(A - 7 [B]

I
An

[
al - -

TAJ =
" 92-- 92n

"an ann- . .
Ann

Ex3T [x =

, xz .
- -
xn]

[BJT =

[b , b2 .
. . .

bn]
n= 2
-

1)
Cramer's rule x

=
al , x) + 912xz = b1
Jac
D =
Ja, eer) ar

ac , x1 + 922xz = be
Jai
x

- a a
Xs

S
2

&
>
X2

&
I
2

XI
>

XI
>
- Forward elimination
Elimination
Gaus Back substitution


>
-

Naive
91X2 An b)
all , + + .
- -
- xn = -

921X1 a22x2 + A2nXn be


+ . - -
=
-
-

i ,

anix ,
+ anyt . --Ann Xu
= bn
-

S1

Multiply equ0 by a

92X
q - - - an
+

=
:
a n

-

al , x1 + 12Xz + ....
a in xn = bl

922 x2 + -
. . .
ain Xn = b

asxz = - . . - An xn = bl3
S

an2 + . . ..
. .
An xn = bu

Now the similar


; doing steps ;

A , nxu b
91 912x2 ,
=
+
x1 +
- -
-

a x + . . . . 92n xn = 6

II

A + --
asn xn = by

s
Ans
/

Xn -- -. Am Xn = bu
Finally
would be
the last step ;

all xi + a *2 + . . .

anyn = bi

a x + - - -

A2nXn = be

"

anyn =
by
as Xs
+ - - -

.
by
n'
Ann xn =

forward
Elimination
for (i i i ) E
= 1 n 1 + +
; ;
+

for (intj = in
; jn ; j+
+
) b

factor =
i
a ii

for (k = i ; kn ; k + + ) E

Aja =

Ajk-factor Air

3
bj bi
=

bj -

factor

3
3
Back
Substitution

xn =
b n'
Ann
i >
- n - 1 to 1

X- · i

for (inti m
;
i < 1 i
) E
-

=
=

for (intj ) E
i
j j
+ 1 = 4 + +
;
=

Sum =

bi-Aijj
3
Xj =

1 i
3

Gauss
Elimination

) E
for (int
1 1 k ++
=
4 = n -

; ;

for /inti
=
1
;
i < n
,
i + +
) E

fac G
=
e

for (intj = k
, j
= n
, j +) E
+

aij aij fac Ghj


= -

3
bi bi
fasb
-
=

Xn = - - - -

=11 i ) E
for (inti
-

1 -

n ; ;
-
=

sum-bi

for (intj = it
; j =n
;j )E
++

sum-sum-Gij Xi

3
Xi =

a , ;

3
Operation
J

counting
S

K = 1

i =
2 to n -
/- 1) iterations

melt/div I

j = n

[ mult-1
,
sub- I

melt-1 such-I
,

mult 1 + n + 1 -> u + 2

sel >
- h + 1 >
- UH
K i Add sub
-

I <
ton(n 1)/-1) +
(U + > (n 1)-

r(n-es
< (n + 1) (n-2)
2 3 to n

:
/

k # + 1) to n
(n- k +
2)(n -) (n + 3 -

1)/n -

m)

Total addition :-

# (n k)(n -
-

k + 2)
K = 1

=
k =

*
+ On)
K=

n +

E k
= =

1 + o(n))
K= 1

⑪ (n2 -
2nk + 2n + m
=

2t)
k= 1

=
n2(n 1) -
+ 2n(n 1) -

-
(n + >
2
S

=
n(n -

1) (n 2)
+ + n
=

(n -

1) -

n(n ) +

/Gn
+
+
n( +
=
n(n x) -

(n + 2 + n -
1 +
2)
=
n(n -

1)(2n + 1 +
21]
-
n(n -

1)( 1) + + 2n -

=
n(n 1) -

(s) +

Sn(n 1)(2n +
1)
-
=
Total multiplication : -

(n-1) (n - x+
3)

-Ink + sn + -B

n(n 3) )
#)
+ (n
=
+ ·
- 2n -

nice
+

=
n(n 1)-

(n + 3 =

= +

]
=
n(n +
)[0x
6 ]
+ 8
- -
9 + ch +

n( (2n 8)
=
+ +
2nx(n u)
=
-
+

En(n -

x(2n 1) +

=
n(n
= 1)[2n + 8 + 10n +
s)

n(- (kn 13]


= +

- :-
subshlution
For back
- nc + o(n)
Resolve the case
of coefficientbeing
Zero >
-
Pivotting

example
-
3x 7X3 = 2
OXI
-
+

3
+ 2x2 x3
=

X/
-

5 X1 - 2x2 + 0x3
=
2

↓ 3rd
row

Pivoting

0x3 2
5x1
=
- 2x2 +

x1 + 2x2 X3 =
3

7X3 2
3x2 + =

OX1
-
Eliminate XI

2
5x1 -

2x2 + 0x3 =

A x2 + An cs) = b ,
,

B xz + B2 xs =
be
,

Gause Jorden

La =
All 912 913.. -

aman - - -
b2

932 As -
by
Sat 3rd -> 9 : 30am-complete tab

Sat 17th -
Quiz-1(blance on)

Gaus
For
I C
J -
0 . 1 0 . 2
; cas

0 .

17 -0 .

3" -19 3
.

0 3
- -
0 2 .

10 ! 71 4 .

I I
I O OI
3 . 0

"
O I O -
C- S

O I 7 0
O
.
t
Normalize frist row - 3

.E
G
removal
of
same as

from
.

row 2x3
.

I (
, 2 6
I -

0 , 03
-

0 . 06 .

O 7 : 0-0 23 .
i -

19 5 .

f 0 19
,
10 7
-

.
. 08

Step-2 Normalize second row - + 7

rosese00)
·

C I

O
-
0 . 04
-5
Normalize Sedrow + + 10 01
.

Xs 1st & 2nd


removal
of from

see book Total #op-n3


Chapera's

LH
decomposition
↓ ↓
lower upfer
triangular triangular

[A7EX3 -

GB3 = 0
-

0
[u uu Ex3 Go to
.

=> [V7Ex 3 -

ED] =
0

[27 =

[I I O

I
-

(3)

So
;

< [[v]EX 3 -ED3]


[A][ x 3 EB3
-

=
[][U] = [A]

[L]ED3 =
EB3

[A]E x 3 =
[B]

↓d
[V] [I]

]ED3 =
EB3
- Forward
substitution
ED3
gives
[U]Ex 3 =

ED3
- Backward
substitution

gives
Ex3

Even keep B
if we
changing ,
we

don't have to do elimination


to
just
and have
again again ,

backword salistitution
do
forward I

.
Ex3
to
get ED3
and
[ I
All 9, 2 913
O A als

O O
as"

191

[N]

i· I
912 913

92' as

O As

III
I I
All ,
a 2 913

A21
9 An a
S

as as

A31 a + as gat aals'


+ ass'

[A] -
[A]

TA ] [A] [I]
+ =
, (A) C
X I
I

,
X2

I
=

I. 12 Is

(A)(X , ) =
I ,

[A] (x s] =
Is
zea
(o O

Xs
bas
=

for (inti
=
n + 1
,
is 1
,
i -

1)
E sum =
bi

for (intj j j + +)
=
i + 1 = n
,
,

E
sum-sum-AijXi

3
3
Fitting
Y Y
a
N *

- N
N

* #

> S

* X

Regression Interpolation

↓ ↓
low errors
When errors are

significant
Regression
6-05 6 .
12
6 .
13

7-05 7 45
6 .
45 .

j &
=

Sy =

v
Sx =

E(yi j)2 -
-
Y

Least-square Regression
>
- Limar least-square regression

(X/, Yi) ( X2 ya)


,
. . . . .

nyn
>

90 + a, x
y
=

risidual
Error on C=
Times-Fifit
Criteria for Best fit
S
i = 1
e;
X

*
M

I ①
&

·
sum
same
Zei
Y

Elei &
& Q

...
.....
x ②
.

-
same
-
x

q(ei
-

>

E e:
2
-
-

Sn 2 =

(i au -
a, xi)
=
-
J =
2 Elyi-ao-axi)

↓ = -2 xi (yi -so-aixi)

a & Exi
. =

ii yi
-

n[xi" -

(Exi)

=
i
a,
a
-

=
.
Se
S- -

n 2


-

Standard
the
error
of

7
- -

estimate
& * =
*

X
#

&
ru =
$Sr

St

r 1
perfect fit
=
-

r = 0 >
- No improvement

BY
xe
y
=

Ex
ya

I
eny
= enc +
Bx

=
eny

>
X

<XB
y
=

eny
=
lux + penx
LiSat 7/2-9am-10am

(CC Lab)

Curve
Fitting
Regression (Least square regression]
Xi
Ji X


X
XI
Y X

, 90 a xi
Yi
-

= ,

i
7

Xn
Yo
Se =

/ min :

Sn =
(yi -
90 - a , xi)
↳ = 0 =
- 2 (yi -
a -

axi)


=
0 =

-2 (yi - au -
a , xi)

; =
a. + a
. Xi

xigi =

an xi + a
,

Any
&

xeBX en
y
= enx + Bx
y
=

S
auP
y
=

eny = enc +
penx
enga
y
= x

+
* ↳
1 Et E
*
= +
en x

Yet i
A

+ x

X +
x
* x

data
points
be
fitted
can
n -

uniquely by
(n-1) degree
polynomials

Polynomial
Regression
+ 92x2 + 2
y
= a. +a , x

Sn =
&ei = (Yi -au - a , xi -
anx :3)
sa
= -2
E (yi -

ar -ai -

auxi) = 0

& =

a + a xi +
An

= -2 yi-au-axi-a ;
xi

Exit Ex
& ii =
a. Exi + a as
I

-a0 -axi-anxit)xi
=
-

i = 0

= as
Exi an
Evi+ an
Ex
)
N

+ a2x" amx* + e

y
= 90 a , x + + ....

S
Sy/x =

n -

(m + 1)
ultiple Linear Regression

90 + a , x) + 92x2
y
=

Se =

Lyi-90 -
a. x , i -

anxi)

a
= -2
(yi- ar - axi-axi) =
Generalized linear least
square regression

arzo + a, z + 927z +

y
= - -..
,

Amm + &

Poly -
: z
.
= 1 7 = x zz = x
...
Zm = xm

to =
1 1 = x E =
X
. . .
Em =
Xm

We can have X =

anything (even-inx)

EY3 =
[z][A] + EE3
[ 7
Zol Ex .....
Emi

12 Zm2

[z)
02 -
. . .

' i !
'

Z On
Zen -
--
↑ Emn

n - no
of data
points
variables
m - no
of in the

model

n > m +1

[x3+ =

(y y . .
. .

Yn]

[A3T =
[ao a . . .
.
.
am]
Sn =
(i -
azji)

((z) (z]][A3
+ =

((Z]" EY3]
Check
Y 00 + 9 , x

for
=

] =Say
EA3
T,
x
(2) =
,

X 2

(73t =

Exix]
((z) (z7]SA3
+
(1 =

=(x + ](i x
]] (i)
-

] [a]
as aa
-
RHS =

[ 7 Cata]
Saotas a )
-

So IHS = RHS
Non-Linear
Regression
Linear least .
square regression

=> 0 zo + 917 , + ... mmte


y
= a

EY3 =

[2J[A] + EE3

=> se
= (yi -

ajji)

[2] [2][A3 =
[I]TEY3

↑4)
-

f(x) = 90
(1 - e
Newton
Gas Method

Yi =

f(Xi ,
9.
,
9) . . .
am) + ei

a's -
non-linear

yi
=
f(xi ,
90 , a)

%
Gaus of 9. 9 , -

gi
=

f(xj + 1) =

f(xi)j +

bily
* a o
W
T

Sf(xi)
/
higher
+ order
i ga , +

Ja
terms
-

990 =

00j Doj
-

+ 1

a G, A
j
=

j
-

+ ,

f(xi)j
(i) 1:
>
yi
-

90
-

↓xi) +a
,n

ED3 =

[2; ][A]
-data points

[2j] =

[ S
s
'
I
Offens Jon

[2] [2] [5A3 [27 ED3


+
=
Regression
Non-Linear
0 25 0 75
1 25 1 75 2 25
X
. . .
.
.

0 28 0 57 0 68 0 79

Y
0 74
.
.

.
.

-
fit 4)

f(x) 90(1
-

=
-

Gues90
Sr = 0 . 0248

~ a,

6 = - = axe
I I
0 .
22 , 19
0

2 =

0 .
52 0 . 35

0 .
71 0 .
35

0 . 82 0 30.

0 .

89 0-23

Yi -

f(xi)

1) 20 -0
0

ED3
.

0 .
57-0 52 .

- 68
0

-0 82
0 74
.

0 . 79-0 .

89
[25(2) =
C 00]
↳ multiply by A]

[27 ED3 =
E80)

[A] =

Fo] -
Aj +


Se

Eal
An
,x
&h
j
+ 1
,
Interporation
(n + 1) ->
datapoints
t
fit order
polynomial

is Newton's Divided difference Interpolation

is Lagrange Interpolation
is Newton's
Divided
Difference Interpolation
A

Linear
interpolation
= -

f(x)
- -

,
=

....

i
f(x)
-

f(xo)
=
-

o xi
S

=
j(x0)
b
f , (x) = +
xr


Linear interpolation
Quadratic
Interpolation

fc(x) = 90 + a, x


+ anx2

I
&
I

= bo + b , (x -
x c)

+ bc(x -
x0)/x xi)-

at X = Yo

bo =
f(X0)

at x = X/

,
bi

1
=
at X = x2

ba =

-f(x) - f
X2-X1 X1-Xo

-2
Yo -
Newton's
Divided
Difference Interpolation

* int data - n-order


polynomial

f(x)
=
bo + b ,
(x - x
0) + bz(x - 0)(x
x -
x, )+

. . . .

fi(x) =

f(x0) + 80 (x - x

↳ L
bi

f(x) = bo + b , (x - x
1) + bz(x -

0)(x
x - x 1)

put x = Xo => bo =
f(x0)

b
put
x =
x => ,
= f)
XI-Xo
at X =
X2

b2(xz - x
0)(xz -

x.) =

f(x2) f(xo) =

- No (x2 -x

f(xc) -

f(x,) + f(x)) -

f(x0)

- No (x -

(f(xz) J(xy) [f(x) f(x))[1 =


+
=
-
-

b =
=
l

X2 - Yo

& Divided difference approximation of the

2nd derivative
bo =

f(x0)
bi =

f[x ,,
Xo]

bz =

f(x z
>
X
, , Xo]
!

bn =

f(Xn ,
xn 1
,
- -
-
xi
,
x0]

where

f(xi xj)
yes
=
,

- (xi +j x a] =

8
+j) f(xj +] xi
-

, , ,

Xi -Xk
S

, durced
th
n
/
difference

8) x0]
H
. -f.-
Xu
n
,
. .
-
1
,
=

I
Xi f(xi) first second third

bo
O Xo f(x0) -
>
by
f(x1 ,
Xo] b2

Ele
-
I F(xc xo] ,
x,
-

>
-
by
S XI ,y
,

-
2 >
- X .
)
&[s ,
Xi ,
D

S 3


have

they
can

any
spacing
Tru Value
Value
ex-
- of In 2
en 2 = 0 .
69

Xi f(xi)
I
en 1 0
=

1 In 4 = 1 .
38

2 In 5 =
1 . 60

3 Rn 6 = 1 . 70

Linear interpolation using


In 6
1) In 1 2

Get In .?
2

In Enu
2) 2nd order >
- 1
,
,
2n6
In 2
get ?

3) 3rd order >


- Ins ,
ent ,
ens
,
en 6
2) f(x)) =
bo + b , (X -

Xo)

bo =

f(Xo) =

f(1) = 0

xf) =
bi =

1
bi =
0 = 0 .
34

f(x) = 0 .

34(X Xo) -

f(2) = 0 .

34(2 -

1)

f(z) = 0 34 .

34 %
Error
69 . 0
0 100
. x
=
.
=
50 . 72
%

2) f(x)
=
bo + b , (x -
x o) + bz(x xo)(x xi)
- -

bo In 1 0
f(x)
=
= =

6
1
= 0 =
=

be =
1 +f
Xz -
XI
-

He
XL -

Yo

-0
1
= :

6 -
1
o
= -
0 . 051
(() = 0 .

46(X -

1) -
0 .
03/x D(x y) -

f(2) = 0 .

46(1) -
0 .

os(1) (-2)
=
0 46. + 0 .
102

=
0 . 562

x()
0
error
= .

562

=
18 . 55
%

3)
f(x)
= bo + b, (x -

x 0) + bz(x -
x o)(x -
x 1)

+ bs(x -

x 0)(x xi)(X -
x 2)
bo =

f(x) = 0

bi =

x) =

10 =
0 46
.

XI -

Yo

bu = fly) -

f(x) - f(x)

-
=
1 60-1 38
.
.
0 . 46
--

s -

y
0 4
-
.

s
-
1

-0-06
=

to -s -
x I
0 2 -0 01

=
=
-
.

0 015 + 0 06
by
-
.

009
-

=
-
0 .

6 -
1

f(x) =
0 .

46(x -

1) -
0 .

06(x 1)(x 7) - -

+ 0 .

009(x -

1)(x y)(x >) - -

f (c) = 0 .
46 -
0 . 06 . 1 .
( -

2)

+ 0 .

009(1) ( 2) ( 3) - -

=
0 46 + 0 12
.
. + 0 . OSY

= 0-634
-0 634
error
= 069 .

x 100 %
0 .
69

= 8 .
11 %

Il Lagrange
Interpolation

fn(x) =
Li
f(xi)

↳:
=
n = 1

fi(x) =

Lof(xo) + L , f(xi)

f ( (f) + (
=
,

n = 2

(,
fc(x) =

Lof(o) +
f(x ,
) + 22f(xz)

-( f(x

f(x) e
(X
x0)(x x1)
- -

f(xz)
(Xz x
-

07/xc - xi)
Clie
Spline
Unconditions

① ai -,
x ? + bi - ,
xi) +
2 - ,
X ; + Ai -
1
=

f(x))

aixi + bix; + (ixi + di =

f(xi) Jen

② Exterior points

③ Math on the 1st derivation

④ Math on the 2nd dirivation

3rd
⑤ Math on the derivation
Interpolation
Slin
(n + 1) points
data

fitting in the with


degre
polynomials

. .

- O
- .

Linear
spline

f(x) =
j(xi) +
fi (x
Quadratic
spline

f(x)
:
=
aix + bix + Li

(n + 1) data
points ,
n intervale

In unknown
coefficients
Las ,
be
,
(e)

Conditions
value at /1-2) interior knots
① Match fn
the

Ai-Yi-3 + bi + Xi + + (i + =

f(xi 1)
-

9 Xi +
+ bixit + (i =

8 (xi)
2(n -

1) =
2n -
2

② End
points
b
a , x02 + xo + (1
f(x0)
=
,

anxn anx
O
+ + <n =

flyn)

③ First derivative at interior knots

b
f(x) =
2ax +

29i + Xi +
+ bi 1
=
29 ; x ++
+ bi

T
for =
2 ..
1
3 5 4 5 2 0
9 0
X
.
. .
.

f(x) 2 .
5 1 .
0 2 5 .
0-5

-d
2 .
0
3 5
.

90x2 + box + Co = 2 5 .

a , x2 + b ,
x + 4 = 2 .
5
0 /
12 . 032 .

(2 .
0) .0
2 /

Qo

bo

Co

as

by

Ca
Cur withSinusoidal
felling
one
functi

& (t) =
A ,
+ C
(os(wot O) +

= Ao + A , <os(wot) + Bisin (woth

Sa
= -[Au + A, (woti) +

Bein(n)


Enin(wot) Eein(wotcos(wot) Evini(t)
↓ - data At
equispaced

-
7 (N 1) At
-

Scout -
in what
period

I ·
Nn/0
·

Ao =

E
Al
= yi ca/woti)
=

B1 =
yisin(voti)

(H)
j(t T) =
+

f (t)
= 90 + a, cos/wot) + b , sin(wot)

+ as (os/2wot) + bc ein/2wot] + ...

- a
+ [Acos(not) +

bein / wot)]
E
Wo =
a.
# ) f(t) a+
=

T
T

S f (H) <n /Wot) =

Jaocos(
O T
will

+
SEA ( (Kwot)
Coscoot

(wot]]
O
+ bei

S
cas not
O
& H <OWOH)
S
2
E
=
+ 9 Cos (K wot) ·

+ ↳

am =

effcos(not a

b =

Esfsts ein (worsat


E
I Ec c
=
-

+
-

Le f(t) =

I -

F + C
E
I
-

* +
I

R
T
M
~
T/2-T/y
< I

-
I

V
T/2
I >

Ao = 0
bi = 0

Th

=ESJCH cos (KwotAt the


-T/Y T/y

=
-

+
(coswort +

E (coswot t

T/y
-

2 -

+2

E(cos(wrt) It

-
=

7/2
[s] +
*
-

E
T/y
Two
=

F (in S] -
win
(o()])
↑ (no] -
ein

)
-

(ein(wo(E)) -

em)]
=
-
ein
(WE

=
-

sin
(E

foot) cosnots
f () =

110 -
+ (Swot) -
In
fourier transform
- /a periodis)

einot
J(t) =
+

f(H) + (iv) eino dwo


=

(iwo) e-rotat
F fits
=

Fi Inewon
Fourier
Discrete Transform
A

........

>

N In
>
-
n = 0
,
. . .
N -
1

F =
fu eiwon
for
= u ... Na

Fenne
In =

Fiz =

[fucos(won) + :
8n ein (won]
Pis 1 k)2
=
=

Announcements
-

GPM-midem
1) Today copy

2) No eas on Wed
(27/3)

3) Extra class on Fri (29/3)

4) Luiz 2 on Sat <13/) 10AM


Numerical Integration &
Differentiation
Simple Contentions
1) Function

2) Complex continuous
function

3) A talulated
function

Non-computer method

Y
Y DYDX &

Y -
S
O

3 8

6
3
9
j

S
Newton-Cotes Scheme
Integration

C
b

=
I Max =
bu(say

a2x) anxh
fn(x) = ar + a, x + + . . .

is Closed Form

nGen
fouSnee Rule
auestop - lanx
ang
height

I =

(f(x)dx =
Sfilax

f , (x) =

f(a) +
6p (xa
I =

((f(a) +

8 f(a) (x-as]
(b a)
+

=
fas/b-a) + fa a
2

+
a
I = (b -

8(b))
a)(b +
f(x) n fly
b(b)
Error

f(a)
-
eheight
. . . . . - -

J
A b
Y

Error (Box 21 .
2)

M
MU
a
Error

.
Et t (b a) 8" (E)
= -

8b
Ex- his between a

Reducing Errors
by dividing
the interval
&

b
A
-

↑ I
/Xo X , x2 -
. . .
xn)

a = ba
=
X2

=
=

e(f(x0) +
f(x)) +
(f(x2) +
f(x))
t -...

I =
z [f(0) +
2 i) +
f(xn)]

Ex =
-

bas " i

Ex =

-as M
h b
a
As =
=

( h
a
Et = -
Et ~

0(h))

Qua -

f(x) = 0 .
2 +
25x - 200x2 +

675x3 - 900x" + 400x5

a = 0

b = 0 .

f(0) =
0 . 2

232
f(0 .

8) =
0 .

+ 252)
0(0
0 1
0
.

I = .
= 0 .
Et =

+(0
- .

0)3 j

-
0 51.

J' = 2s -

400x + 675 .
3x2

-
900 .
4x3 + 400 .
5xY

" =
400 + 675 .
64 900 12x2
-
.
-

+ 400 .
20x3

=
So Ex = 2 . 56

hi h2

I /hi) + Elhi) = I/h2) + E(G2)

Eh= h
e

=> E(h)

=
I =
I(hn) + 1 (2(a) -

(c))
1 -

/
+ O(hY)
fu() = 2 (i()
f(xi)
i = 0

where Li =

/x
(j + 2)

L (x)
f(x) = ;
j(xi)

Lo =

j -
= 0

(j + q

1
=
(j = 27

12 =

*
(j + 27
f2(x) = 20
f(x0) + L ,
f(x , ) +
22f(x)

I =

ffz(x) ax + E
b
-

2
-
a
= h

a X b
For dala
equispaced
-

;
&

Yo XI X2

L L
XI- Xo -
e er h

X2-Xo = 2h

x2 -

x, = h
Numerical Integration
b
Trapezoidal

·
Sf()d ↳

L
Simpson /3

Simpson 3/
I h

*
f(x) *
f(x)
Ref
-
0 8 0-2 6 40
2 456

[
.
.
.

0 44
, 12 1 589
.

0 .
2 842 .

Co .
22
1 .
30S 0 .
54 3 .
507

!
S0 - 32 1 74) 0 64 181
.

3
-

0 36 70
.

- 07Y
2 0 .

2 . 368

jumps
Gaus
Cuadrature (Integration of Eg)
f(x) n

e b
here
locke ie
s
sen

,
Method Undetermined coefficient
of

[ =
(of(a) + < , f(b)

↓ result
exact
-
constant line
for straight
&

y
a

1
y
=

<
" " & X

(bIa) b
-
-
- a

I
-
y
&

- (b= !
< >
X

i
b-
-
a

L
v

constant (=
-
for
Co + c =

S1 .
dx

(b
=
Co + 21 =
b -
a + b a =
b -
a
=

I 2

o
C + c ,
= b -
a -

0
line
ht
for b
[
- a

c(b=2) + c , (b=2) =

Sxdx
-

p)
=

c(b) (b) + = D

Co = CI

= Co b
=
a 4
=
=
I E
(of(x0) + ( ,
f(x))

exact results
upto 3rd order
polynomial
/
y
=

x
y
=

x2
y
=

x3
y
=

let's assume a = 1
,
b = 1
/for making
Algebra
easier)
I

(of(x0) + ( ,
f(x)) 1dx

=
Co 1 + C ,
1 = 2
.
(of(x0) +
4 f(x)) =

-
(xdx
I

Co . Xo + C , X1 =
0

(0
f(x0) (
+ ,
f(x)) =

(x
-
dx

(oxo + 2 xi
=
,

(of(x0) + 2 ,
f(xi) =

-
S X3dx

Coxos + 2 +13 = 0

Solving the 4
equ for
Y unknowns :-
Co =
C1 =
1

Xo -

I
VS
x1 =

J(t)
here =
f( =) +
=
X =
90 + 9, Xd

X - a b Xd =
-
1 I
, ,

I
a = 90 -

a)
= 90
ba
=

b = 90 + a ,
As = b a

x = b
=
a
+
(b)

dx =

(b=a) dxd
f(x)) 0 2 + 25xx 200x2 + 675x3
Lees
=
-

" S
-
900x + 400xa
!

a 0 = be 0 . 8

x =

b
a +
(b) x

x =
0 . 4 + 0 . 4Xd

f(x) = 0 .
2 +
25 (0 . 4+ 0

200
(0 4x)"
+

25/0 400 n)
-

.
4+ 0 .
.

900 (an +0 .

ux)" +

400 (0)
= 0 2
.
+
25/0 -y)(1 + x)

-
200
(0 . 4)2(x 1)2 + + 675
(0 /x 1)
.
+

900/0 .

4)"(x + ) Y + 400
/0 4)S/X6)S
.

f(x) = 0 .
2 + 10(1 +
x) -

8(x 12+

15 /XAy
+
2x8(x +

9
-

+ #Hs
I =
f( b) -

+
6(5)

1 .
822
=

Simpsons
to
similar

I E (of(x0) + 2 ,
f(xi)
+
(cf(x3)

x* /with nohe
accurate upto
Differential Equations
Ordinary
L
mar ODE :

an(x)
y + an -
, (x)
y +..

ao(x)y =
f(x)

Solving =

f y) ,

ma C
0
+ + x
=

a
y
=
0
may cy + kx 0
-
=

d+

We know (Xi Ji) ,

Initial condition -
Boundary
condition
4 =
f(xi ji),

Yit Yi th
=
+

Ever
method

t
stone

+ , file

+ - --

Ea =
0(h]
Predictor corrector
method/Idean/modified
- -
Enter
-

Y o =
f(x , y

j
-

·
-

-
+

Yi
I > X
Girl
X,

Yi +
=

Yi +
f(xi fith
,

f(xi +
, y; 1)
+
Yi get a fin
i
=

Yin
=

Yi +
Yin +
y, + 0))

gi +
yih +
1 :
+ o(h))

yi n[y; +
=

+ o(h3)

yi +
n[y ] i
+
+ o(as)
ex 2x 12x
y
+ 20x + 8 5
-

= -
- .

X 0 1 h
=
5
y
= =
0 .

a =

f(x ,
y)

f(xi yi) ,
=
-
2/0)3 + 12 (0) - 30(0)

+ 8 .
5 = 8 5
.

(0 5) 3 21
true- Y
.

- =

Euler
-

oh
2
Ji Yi
+
=
+ 1
& S
X S

42 -
1 0 5/0 S)
-

=
+ .
.

=
1 + 4 25
. 25 = S .
Et
- 21
=

=
63 5)
.

Modifiedzube

Yi +; = 5 25.

ay(x = 05
, y scs)
= = -

2(0 12s) ,

+ 12(0 .
25) -

20/0s)
+ 8S

==
6 2 .
+ 3 -

10

+ 0
.

= 1 , 25

f (0 ,
1) = 8 5
.
Aug f
= 4 . 875

Yi 4 875x 5 3 437
0
1 +
. =
.
.

=
+

Et = 7 07
.

f(x Y)
,
a

-
S >

v
ODE-Euler - 0(h) >

=> Predictor corrector OTh3)

Solvey +
xy
= 0 I .
2 .

y (0) =

Evaluate
h
y/0 05)
using predictor
= 0 .
05
. .

method
core. .

Compare with
analytic method
.

Exercise +
↑ x(0)
: 1
xy
=
+
-

Conferent E a =

ty + x

y(0)
=
Range
Kutta Method

it
=

Yi + &(xiyin) h

& (x :
yi h) >
- Increment
on

↳ Representar slopes in the interval

0 9 , + A22 + An
= ...

As &K's are constants

ki =
f(Xi yi)

kc =
f(xi + p(k > yi
+
q k(h)
,

ks =

f(xi +
pas Yit 82 /
h +
92k h)
:

kn =

/Xi +
Parks Yi + ch +
make ...

.....
Un , n +
kn h)

p's &q's are constants

donder,
i

als + anah -

ki =

f(xi yi) -

h) -
f(xi
k
pih i
+
q
-
,
kz = + ,
,
Yit, =

yi +
f(xiyi)h +

f yi a

Yi + 1
=

yi
+
f(xiyi)h +
(+
-

kc =

f(Xi +
p , h ,
yi +
q ,
k, 2)

f(x y ) b = o
n ka
: + +
q
=
; , ,

+ 0(hz)
-

g(x + e
,
y + s)

=
g(x ,
y) +

rg
+
S18 + - -

Jy
Yi + 1
=

Yi +
(a) + az) f(x y)
,
a +

Campi aq
kint
+
,

Comparingeq 2 ( : -

a1 + 92 = 1

azp1 =

a
29 E
=
,
Suppose As is chosen
,

al = 1 -

92

bi q
ca
= =

a .
= 92

=> Predictor correcte


pi q
1
method
=
= -

Assume ac = 1

=> al = 0

p, =
q ,
=

E
=> Midpoint
method
k2h
Yi + 1
=

Yi +

kz =
G(xi + A , yi +
1 )
I
order R .
K.

Yit =

yi + (a , k , + a212 + asks

auku]h
+

# unknown =
13
/A , a2
,
as , an,

P1 ,
b ,
s
, q ,

H qu
qs)
, 92 > 9 s1 , qs2

11
F
equations
verson
-
Imp
.

Yi+
=

Yi +
t(k) + 2kz + 2ks + ku) a

ki =

f(xi yi)
(c =

f(xi + 2 , yi
+
zk h) ,
(s =
f(xi +

th ,
yi
+
1k h)

kn =

f(xi + h
, yi +
ksh)

Assignment
-
->

Say (dx =
(0s -
20x + 12x) -

2x))

0 x 10x4 ux)
-
y
= .
-
+

=
+ C
1
for y
=
0
x =

1 =
C

=> C = 1
10x2 + 4x3 xY
Y = 8 5x.
-
-

+ 2
I

RY
+ /805 + 2 .
5

2
Luiz
Saturday (13-4-24)
: : 10 AM : <C Lab

Syllabus :
& Differentiation
Integration

[ I
For end 2 : 00 hos written exam
rem :

1 : 00 has - hands on

ODE : RK method (Initial value


problems

a =
f(x y) ,

Yit
=

Yi +
p(xi , y , a) h

p = G ,. + 12 + -.
Ankn
* f(x y , y y
...

= ,

↑ =

f(x , y , yu .

yn)
I

dyn 8(X Y Y2 y
...

=
, ,

Problem-2
:

Damped Harmonic Oscillator


-

mat
X = 0

t = 0

X= ?
j =
?
2 #
-⑪
1x
>


,

ma
That
KI OO

xi(H) A
B
: +
x

X2(t)
C
:

DA
+ kexo
Optimising
-
step size

- .
Adaptive
RK method

Method I
(particular RK)
-

① Start with h to
get fith
twice
② =

1
-
Apply update
to
getyith

==
(

large
,

-matte en
I h is not

good enough)

Method-2
-

take
I
① Apply
RK4 and RK5


If RKY & RKS

are
matching not
matching
↓ ↓
his
good take smaller

h
enough
- -

Boundary
value
problem

y G(xy
X
yo
0

y
= =

x
Ly yL
= =

need
o
!
a at

x = L
T = To T =
Tw

T(X)

Rate
of flow of heat
(influx) at

H ↓
Area
KAI Es ,
o
&X

Ihermal
Conductivity

Rate of flow of heat


/outflux) at x + d

ka
[ +
/]
d
=> =

Non-insulated
iron roo ex
+ dy

!
d
0) 11
*
+
x=

To (sounding

=>
a + h (Ta -
) =

Using finite differences method


,
we can
n
find coupled equations
.

Finite
Difference Method

T =

i+
= 2T ; + Tin
dx2
h
2

= 0
in it i
Finite ↳
h
X = L

X
T = TL
To
T =

Tix-21/Ti-Ta
-2
he
[A7 [x3 =

EB3

ex-write down this


- eq" for each
of
these
points
.

You might also like