You are on page 1of 11

ASSIGNMENT 2

by EMCS 257
May Pyae Phyo Thu

Evaluate the first derivative of y(x) = sin (x) for x = 1 and h = 0.1, 0.01, and 0.001 by the three difference schemes:
Evaluate the errors by comparison to the exact values.

y(x) = sin(x)
x= 1
h= 0.1 0.01 0.001

y(x) h y'(1) y'(1) y'(1)


sin(x) 0.1 0.497364 0.581441 0.540077
0.01 0.536086 0.544501 0.540300
0.001 0.539881 0.540723 0.540302

y'(x) y'(1)
0.540302

error 0.042939 0.041138 0.000225


0.004216 0.004198 0.000002
0.000421 0.000421 0.000000
nce schemes:

y(1+h)− y (1 ) 1st
y ' (1)≈
h

y(1 )− y (1−h)
y ' (1)≈ 2nd

h h
y( 1+ 2
)− y ( 1− 2
) 3rd
y ' ( 1)≈
h
1st d 2nd 3rd
y(x) h y'(1) y'(1) y'(1)
sin(x) 0.1 0.4973638 0.5814408 0.540077208
0.01 0.536086 0.5445006 0.540300055
0.001 0.5398815 0.540723 0.540302283

y'(x)= cos(x)
0.540302

0.0429386 0.0411384 0.0002251


0.0042163 0.0041983 0.0000023
0.0004208 0.0004206 0.0000000
-6.8349349298

y(x) h y'(1) y'(1) y'(1)


sin(x) 0.1 0.4973637525 0.5814407518 0.942574 0.540077
0.01 0.536085981 0.54450062074 0.5403
0.001 0.5398814804 0.54072295128 0.540302

y'(x)= cos(x)
0.5403023059

0.0429385533 0.0411384459 0.0002250978


0.0042163249 0.0041983149 0.0000022513
0.0004208255 0.0004206454 0.0000000225

Forward backward Central 0.042939 0.041138


y(x) h y'(1) y'(1) y'(1) 0.004216 0.540302
sin(x) 0.1 0.4973637525 0.5814407518 0.540077 0.000421 0.540302
0.01 0.536085981
0.001 0.5398814804
0.000225
0.540302
0.540302
Calculate d at x = 1 by using the forward, backward, central difference approximation with h = 0.1, 0.05 and 0.025
√x
dx
a.       Comparison to the exact value and
b.      Using the error terms.

f(x)= √x
x= 1
h= 0.1 0.05 0.025

f(x) h f'(1) f'(1) f'(1)


√x 0.1 0.488088 0.513167 0.500156
0.05 0.493902 0.506411 0.500039
0.025 0.496913 0.503165 0.500010

f'(x) f'(1)
1 0.5
√x
2

error 0.011912 0.013167 0.000156


0.006098 0.006411 0.000039
0.003087 0.003165 0.000010
th h = 0.1, 0.05 and 0.025. Evaluate the error of each result by:

y(1+h)− y (1 )
y ' (1)≈ 1st
h

y(1 )− y (1−h)
y ' (1)≈ 2nd

h h
y(1+ 2 )− y ( 1− 2 ) 3rd
y ' (1)≈
h
1st 2nd 3rd
f(x) h f'(1) f'(1) f'(1) f(x)
0.1 0.488088 0.513167 0.500156
√x √x
0.05 0.493902 0.506411 0.500039
0.025 0.496913 0.503165 0.50001

0.5
0.5
0.01191 0.01317 0.00016
0.00610 0.00641 0.00004
0.00309 0.00316 0.00001
~

1st 2nd 3rd


h f'(1) f'(1) f'(1)
0.1 0.488088 0.513167 0.500156
0.05 0.493902 0.506411 0.500039
0.025 0.496913 0.503165 0.50001

0.011912 0.013167 0.000156


0.006098 0.006411 0.000039
0.003087 0.003165 0.000010
−f i +3 +9 f i+1 −8 f i
f 'i≈
6h

f i+3 ¿ 9 f i +1 −8 f i −6 hf i '

2 3 4
h '' h ' '' h
f i+3
[
=9 f i + h f i +
'
]
f + f + f + .. . . −8 f i −6 hf i
2 i 6 i 24 i''''

9 h2 ' ' 3 h3 '' ' 3 h4


=f i +3 h f 'i + f + f + f +. .. .
2 i 2 i 8 i''''

f i+3 −f i 3 '' h2 '' ' h 3


fi = − h f i − f i − f ''''−.. . .
3h 2 2 8 i

The truncation error is the term:

2 3
3 h h
− h f ''i − f ''i '− f ''''−.. . .
2 2 8 i

.
1 1 2 1 3 1 4
f '( x0) = (
h
Δf 0 − Δ f 0 + Δ f 0 − Δ f 0
2 3 4 )
to compute f(x) = x4, x0 = 0.4, h = 0.2.

f(x) = x4 x0 = 0.4 h = 0.2

x f(x) = x4 ∆f0 ∆2f0 ∆3f0 ∆4f0


0.40000 0.02560 0.10400 0.17600 0.13440 0.03840
0.60000 0.12960 0.28000 0.31040 0.17280
0.80000 0.40960 0.59040 0.48320
1.00000 1.00000 1.07360
1.20000 2.07360

0.256
1 1 1 1
f '( x0) =
h (
Δf 0 − Δ 2 f 0 + Δ3 f 0 − Δ 4 f 0
2 3 4 )
x f(x) ∆f0 ∆2f0 ∆3f0 ∆4f0

You might also like