Sie sind auf Seite 1von 74

01208271

(Examples and Problems for 01208271)

. .
11 2559
TOPIC-01
EXAMPLES

Example1:

FindtheTaylorseriesexpansionforf(x)=sinxnearx=0allowinga5thordererrorinthe
approximation:

Asaresult,fornearx=0,sinxcanbeapproximatedas:

x3
sin x x
3!

Supposethatifyouwanttofindthevalueofsin(0.1),theapproximatedvalue(fromabove
0.13
equation)is 0.1 0.100167 wherethetruevalueis0.099833.Arelativeerrorisabout
3!
0.33%.

PROBLEMS

(Ifnotmention,use3decimalplaces)

Problem1:

Let A=1.22,B=4.56and C=0.79,todetermine thepercentageerrorof(AB)/Cif A,B


and Careroundedoffto1digitplace

Problem2:

TheMaclaurinexpansionofsinxisgivenby

x3 x5 x7 x9
sin x x ...
3! 5! 7! 9!

Byconsideringone,two,three,four,andfivetermsontherighthandside,estimatethevalueofsin
xatx=(/6),anddeterminetheerrorineachcase.Comparethiswiththetruevalueofsin(/6),
whichis0.5

Problem3:

DeterminetheTaylorseriesforcos(x)aboutzero.Evaluatecos(0.1)bysummingfourterms.
Comparewiththeactualvalue.

Problem4:

Let f(x)=2+ex,using TaylorPolynomial(n=3)forestimatingthevalueoff(0.2)aboutx0=0

Problem5:

Determinethefirstfournonzerotermsintheseriesexpansionaboutzerofor

f(x)=(sinx)+cos(x)andfindanapproximatevalueforf(0.001).

Problem6:

How many minimum nonzero terms in the series expansion of sin x about zero that make
remainunchangeinapproximatedvalueofsin(0.5)?
TOPIC-02
EXAMPLES

Example1:(Problem5.6,Chapra)

(a)Determinetherootsoff(x)=1221x+18x22.75x3graphically.Inaddition,determine
the first root of the function with (b) bisection and (c) false position. For (b) and (c) use initial
guessesofxl=1andxu=0andastoppingcriterionof1%

Solution

(a)ThegraphcanbegeneratedwithMATLAB

>>x=[1:0.1:6];

>>f=1221*x+18*x.^22.75*x.^3;

>>plot(x,f)

>>grid


Thisplotindicatesthatrootsarelocatedatabout0.4,2.25and4.7.

(b)Usingbisection,thefirstiterationis

1 0
xr 0.5
2

f 1f 0.5 29.753.34375 99.47656

0.5 0
xr 0.25
2
Therefore,therootisinthesecondintervalandthelowerguessisredefinedasx1=0.5.The
seconditerationis

i xl f(xl) xu f(xu) xr f(xr) |a|

1 1 29.75 0 12 0.5 3.34375

2 0.5 3.34375 0 12 0.25 5.5820313 100.00%

3 0.5 3.34375 0.25 5.5820313 0.375 1.4487305 33.33%

4 0.5 3.34375 0.375 1.4487305 0.4375 0.8630981 14.29%

5 0.4375 0.86308 0.375 1.4487305 0.40625 0.3136673 7.69%

6 0.4375 0.86308 0.40625 0.3136673 0.421875 0.2694712 3.70%

7 0.42188 0.26941 0.40625 0.3136673 0.414063 0.0234052 1.89%

8 0.42188 0.26941 0.41406 0.0234052 0.417969 0.1227057 0.93%

Thus,after eight iterations, we obtain a rootestimate of 0.417969 with an approximate


errorof0.93%,whichisbelowthestoppingcriterionof1%.

(c)Usingfalseposition,thefirstiterationis

12 1 0
xr 0 0.28725
29.75 12

f 1f 0.287425 29.75 4.4117349 131.2491

Therefore,therootisinthefirstintervalandtheupperguessisredefinedasxu=0.287425.
Theseconditerationis

4.4117349 1 0.287425
x r 0.287425 0.3794489
29.75 4.4117349

0.3794489 0.2874251
a 100% 24.25%
0.3794489

f 1f 0.3794489 29.75 1.2896639 38.3675


Therefore,therootisinthefirstintervalandtheupperguessisredefinedasxu=0.379449.
Theremainderoftheiterationsaredisplayedinthefollowingtable:

i xl f(xl) xu f(xu) xr f(xr) |a|

1 1 29.75 0 12 0.287425 4.4117349

2 1 29.75 0.28743 4.4117349 0.379449 1.2896639 24.25%

3 1 29.75 0.37945 1.2896639 0.405232 0.3512929 6.36%

4 1 29.75 0.40523 0.3572929 0.412173 0.0938358 1.68%

5 1 29.75 0.41217 0.0938358 0.414022 0.0249338 0.45%

Thus,afterfiveiterations,weobtainarootestimateof0.414022withanapproximate
errorof0.45%,whichisbelowthestoppingcriterionof1%.

Example2:(Problem6.5,Chapra)

Use(a)theNewtonRaphsonmethodand(b)themodifiedsecantmethod(=0.05)to
determinearootoff(x)=x516.05x4+88.75x3192.0375x2+116.35x+31.6875usinganinitial
guessofx=0.5825ands=0.01%.Explainyourresults.

Solution

(a)TheformulaforNewtonRaphsonis

x 5i 16.05x i4 88.75x 3i 192.0375x i2 116.35x i 31.6875


x i 1 x i
5x i4 64.2x 3i 266.25x i2 384.075x i 116.35

Usinganinitialguessof0.5825,thefirstiterationyields

50.06217
x1 0.5825 2.300098
29.1466

2.300098 0.5825
a 100% 74.675%
2.300098

Seconditeration

21.546
x 2 2.300098 90.07506
0.245468

90.07506 2.300098
a 100% 97.446%
90.07506

Thus,theresultseemstobediverging.However,thecomputationeventuallysettlesdown
andconverges(ataveryslowrate)onarootatx=6.5.Theiterationscanbesummarizedasthe
tableinthenextpage.


iteration xi f(xi) f(xi) |a|

0 0.582500 50.06217 29.1466


1
2.300098 21.546

0.245468
74.675%

2 90.07506 4.94E+09 2.84E+08 97.446%

3 72.71520
1.62E+09
1.16E+08
23.874%

4 58.83059
5.3E+08

47720880
23.601%

5 47.72701 1.74E+08 19552115 23.265%

6 38.84927 56852563 8012160 22.852%
7 31.75349 18616305 3284098 22.346%
8 26.08487 6093455 1346654 21.731%
9 21.55998 1993247 552546.3 20.987%

10 17.95260 651370.2 226941 20.094%


11 15.08238 212524.6 93356.59 19.030%

12 12.80590 69164.94 38502.41 17.777%


13 11.00952 22415.54 15946.36 16.317%

14 9.603832 7213.396 6652.03 14.637%


15 8.519442 2292.246 2810.851 12.728%
16 7.703943 710.9841 1217.675 10.585%

17 7.120057 209.2913 556.1668 8.201%


18 6.743746 54.06896 286.406 5.580%
19 6.554962 9.644695 187.9363 2.880%
20 6.503643 0.597806 164.8912 0.789%

21 6.500017 0.00285 163.32 0.056%


22 6.5 6.58E08 163.3125 0.000%

(b)Forthemodifiedsecantmethod,thefirstiteration:

x 0 0.5825 f x 0 50.06217
0.5825+0.05(0.5825)

x 0 x 0 0.611625 f x 0 x 0 49.15724

0.050.582550.06217
x1 0.5825 2.193735
49.15724 50.06217

2.193735 0.5825
a 100% 73.447%
2.193735

Seconditeration:

x1 2.193735 f x1 21.1969

x1 x1 2.303422 f x1 x1 21.5448

0.052.193735 21.1969
x 2 2.193735 4.48891
21.5448 21.1969

4.48891 2.193735
a 100% 148.87%
4.48891

Again,theresultseemstobediverging.However,thecomputationeventuallysettlesdown
andconvergesonarootatx=0.2.Theiterationscanbesummarizedas




iteration xi xi+xi f(xi) f(xi+x i) |a|

0 0.5825
0.611625
50.06217
49.15724


1 2.193735 2.303422 21.1969 21.5448 73.447%

2 4.48891
4.71336
20727.5
24323.6
148.870%


3 3.19524 3.355 7201.94 8330.4 40.487%

4 2.17563
2.28441
2452.72
2793.57
46.865%

5 1.39285
1.46249

808.398 906.957

56.200%

6 0.82163
0.86271
250.462
277.968
69.524%

7 0.44756
0.46994

67.4718 75.4163

83.579%

8 0.25751 0.27038 12.5942 15.6518 73.806%
9 0.20447 0.2147 0.91903 3.05726 25.936%

10 0.20008 0.21008 0.01613 2.08575 2.196%

11 0.2 0.21 0.0002 2.0686 0.039%

12 0.2 0.21 2.4E06 2.06839 0.000%

Explanation of results: The results are explained by looking at a plot of the function. The
guessof0.5825islocatedatapointwherethefunctionisrelativelyflat.Therefore,thefirstiteration
resultsinapredictionof2.3forNewtonRaphsonand2.193forthesecantmethod.Atthesepoints
thefunctionisveryflatandhence,theNewtonRaphsonresultsinaveryhighvalue(6.5),whereas
themodifiedfalsepositiongoesintheoppositedirectiontoanegativevalue(0.2).Thereafter,the
methodsslowlyconvergeonthenearestroots.


PROBLEMS

(Ifnotmention,use3decimalplaces)

Problem1:

Findtherootoftheequation

0.1
f ( x) 4 x 2 0.04 0.24 sin 1 ( ) 10.056 0
x
usingthebisectionmethodwithin2and10asinitialapproximationsand=0.01(or1%).

Problem2:

Repeatproblem1byusingtheFalsepositionmethod.

Problem3:

Findthesolutiontothecubicequationf(x)=x3+4x210=0.Usethestartinginterval[a,b]
=[1,2](=0.01).

Problem4:

Repeatproblem3byusingtheFalsepositionmethod.

Problem5:

Findtherootoftheequation

f ( x) x 3 0.259 x 2 0.023 x 0.001 0

usingtheNewtonRaphsonmethodwithx1=0.0and=0.01.

Problem6:

Find the solution to f(x) = 3ex 4cos(x) = 0 byusing the NewtonRaphson Method and
employingthestartingapproximationp0=1.0(=0.01).

Problem7:

Find the solution to f(x) = 3ex 4cos(x) = 0.Use the Secant Method and the starting
approximationsp0=1.0andp1=0.9(=0.01).
TOPIC-03
EXAMPLES

Example1:(Problem7.5,Chapra)

Thepositionofthreemassessuspendedverticallybyaseriesofidenticalspringscanbe
modeledbythefollowingsteadystateforcebalances:

0=k(x2x1)+m1gkx1

0=k(x3x2)+m2gk(x2x1)

0=m3gk(x3x2)

ifg=9.81m/s2,m1=2kg,m2=3kg,m3=2.5kg,andtheks=10N/m,useMATLABtosolveforthe
displacementsx.

Solution

Termscanbecombinedtoyield

2kx1kx2 =m1g

kx1+2kx2kx3=m2g

kx2+kx3=m3g

Substitutingtheparametervalues

20 10 0 x1 19.62
10 20 10 x 29.43

2
0 10 10 x3 24.525

AMATLABsessioncanbeusedtoobtainthesolutionforthedisplacements

>>K=[20100;102010;01010];

>>m=[2;3;2.5];

>>mg=m*9.81;

>>x=K\mg

x=

7.3575

12.7530

15.2055

Example2:(Problem8.7,Chapra)

Giventheequations:

10x1+2x2x3=27

3x16x2+2x3=61.5

x1+x2+5x3=21.5

(a)SolvebyGuasselimination.Showallstepsofthecomputation.

(b)Substituteyourresultsintotheoriginalequationstocheckyouranswers.

Solution

(a)Multiplythefirstequationby3/10andsubtracttheresultfromthesecondequationto
eliminatethex1termfromthesecondequation.Then,multiplythefirstequationby1/10and
subtracttheresultfromthethirdequationtoeliminatethex1termfromthirdequation.

10x1+2x2x3=27

5.4x2+1.7x3=53.4

0.8x2+5.1x3=24.2

Multiplythesecondequationby0.8/(5.4)andsubtracttheresultfromthethirdequationto
Eliminatethex2termfromthethirdequation,

10x1 +2x2x3=27

5.4x2+1.7x3=53.4

5.351852x3=32.11111

Backsubstitutioncanthenbeusedtodeterminetheunknowns

32.11111
x3 6
5.351852

x2
53.4 1.7 6 8
5.4

x1
27 6 28 0.5
10

(b)Check:

100.5 28 6 27

30.5 68 2 6 61.5

0.5 8 5 6 21.5

Example3:(Problem8.8,Chapra)

Giventheequations:

2x16x2x3=38

3x1x2+7x3=34

8x1+x22x3=20

(a)SolvebyGuasseliminationwithpartialpivoting.Showallstepsofthecomputation.

(b)Substituteyourresultsintotheoriginalequationstocheckyouranswers.

Solution

(a)Pivotingisnecessary,soswitchthefirstandthirdrows,

8x1 x 2 2x 3 20

3x1 x 2 7x 3 34

2x1 6x 2 x 3 38

Multiplythefirstequationby3/(8)andsubtracttheresultfromthesecondequationtoeliminate
the21termfromthesecondequation.Then,multiplythefirstequationby2/(8)andsubtractthe
resultfromthethirdequationtoeliminatethe31termfromthethirdequation.

8x1+x22x3 =20

1.375x2+7.75x3 =26.5

5.75x2+1.5x3 =43

Pivotingisnecessarysoswitchthesecondandthirdrow,

8x1+x22x3 =20

5.75x2+1.5x3 =43

1.375x2+7.75x3 =26.5

Multiplypivotrow2by1.375/(5.75)andsubtracttheresultfromthethirdrowto

Eliminatethe32term.

8x1+x22x3 =20

5.75x2+1.5x3 =43

8.108696x3=16.21739

Thesolutioncanthenbeobtainedbybacksubstitution

16.21739
x3 2
8.108696

43 1.5 2
x2 8
5.75

20 2 2 18
x1 4
8

(b)Check:

24 68 2 38

34 8 7 2 34

84 8 2 2 20

PROBLEMS

(Ifnotmention,use3decimalplaces)

Problem1:

UsetheGausseliminationmethodtosolvethelinearsystem

1 2 3 x1 3
3 1 5 x 2
2
2 4 1 x3 1

Problem2:

UsetheGaussJordaneliminationmethodtosolvethelinearsysteminProblem1

Problem3:

UsetheGausseliminationmethodtosolvethelinearsystem

1 4 4 7 x1 4
0 2 1 0 x 5
2
2 1 1 4 x3 2

2 3 2 5 x4 9

Usethenaive,partialpivotingandcompletepivotingstrategies.

Problem4:

UsetheGaussJordaneliminationmethodtofindA1andthenshowingthatAA1=I

1 4 3 2
2 2 1 0
A
2 1 6 9

8 3 7 5

AdditionalExample


TOPIC-04

EXAMPLES

Example1:(Problem9.5,Chapra)

SolvethefollowingsystemofequationsusingLUdecompositionwithpartialpivoting:

2x16x2x3=38

3x1x2+7x3=34

8x1+x22x3=20

Solution

[A]{x}=[b]
(aDecomposition
[U][L]

[L]{d}=[b]

bForward


Substitution
{d}
[U]{x}={d}

cBack
{x}

Thesystemcanbewritteninmatrixformas

2 6 1 - 38
A 3 1 7 b - 34
8 1 2 - 20

Partialpivot:

- 8 1 2 - 20
A 3 1 7 b - 34
2 6 1 - 38

Forwardeliminate

f21=3/(8)=0.375 f31=2/(8)=0.25

- 8 1 2
A 0 1.375 7.75
0 5.75 1.5

Pivotagain:

- 8 1 2 - 20

A 0 5.75 1.5 b - 38
0 1.375 7.75 - 34

Forwardelimination:

- 8 1 2

A 0 5.75 1.5
0 0 8.108696

Therefore,theLUdecompositionis

1 0 0 - 8 1 2

LU 0.25 1
0 0 5.75 1.5
0.375 0.23913 1 0 0 8.108696

Forwardsubstitution:

1 0 0 d1 20
0.25
1 0 d 2 38
0.375 0.23913 1 d 3 34

d1=20

d2=38(0.25)(20)=43

d3=340.375(20)0.23913(43)=16.21739

Backwardsubstitution:

- 8 1 2 x1 20
0 5.75
1.5 x2 43
0 0 8.108696 x3 16.21739

16.21739
x3 2
8.108696

x 2 43 1.5 2 8
5.75

x 20 18 2 2 4
1
8

Example2:(Problem9.8,Chapra)

(a)PerformaCholeskydecompositionofthefollowingsymmetricsystembyhand:

8 20 15 x1 50
20 80 50 x 250
2
15 50 60 x3 100

(b)Verifyyourhandcalculationwiththebuiltincholfunction.

(c)Employtheresultsofthedecomposition[U]todeterminethesolutionfortherighthand
vector.

Solution

(a)Forthefirstrow(i=1),Eq.(9.15)isemployedtocompute

u 11 11 8 2.828427

Then,

a 12 20
u 12 7.071068
u 11 2.828427

a13 15
u13 5.303301
u11 2.828427

Forthesecondrow(i=2),

u 22 a 22 u 2 12 80 7.071068
2
5.477226

a 23 u12 u13 50 7.0710685.303301


u 23 2.282177
u 22 5.477226

Forthethirdrow(i=3),

u 223 60 5.303301 2.282177 5.163978


2 2
u 33 a 33 u13
2

Thus,theCholeskydecompositionyields

2.828427 7.071068 5.303301


U 0 5.477226 2.282177
0 0 5.163978

(b)

>>A=[82015;208050;1560];

>>U=chol(A)

U=

2.8284 7.0711 5.3033


0 5.4772 2.2822
0 0 5.1640

(c)ThesolutioncanbeobtainedbyhandorbyMATLAB.UsingMATLAB:

>>b=[50;250;100];

>>d=U\b

d=

17.6777
22.8218
8.8756

>>x=U\d

x=

2.7344
4.8828
1.7187
Example3:(Problem10.1,Chapra)

Determinethematrixinverseforthefollowingsystems:

10x1+2x2x3=27

3x16x2+2x3=61.5

x1+x2+5x3=21.5

Checkyourresultsbyverifyingthat[A][A]1=[I].Donotuseapivotingstrategy.

Solution

First,computetheLUdecomposition.Thematrixtobeevaluatedis

10 2 1

3 6 2

1 1 5

Multiplythefirstrowbyf21=3/10=0.3andsubtracttheresultfromthesecondrowtoeliminate
thea21term.Then,multiplythefirstrowbyf31=1/10=0.1andsubtracttheresultfromthethird
rowtoeliminatethea31term.Theresultis

10 2 1
0 5 .4 1 .7
0 0 .8 5 .1

Multiplythesecondrowbyf32=0.8/(5.4)=0.148148andsubtracttheresultfromthethirdrow
toeliminatethea32term.

10 2 1
0 5 .4 1 .7
0 0 5.351852

Therefore,theLUdecompositionis

1 0 0 10 2 1
LU 0.3 1 0 0 5.4 1.7
0.1 0.148148 1 0 0 5.351852

Thefirstcolumnofthematrixinversecanbedeterminedbyperformingtheforwardsubstitution
solutionprocedurewithaunitvector(with1inthefirstrow)astherighthandsidevector.Thus,the
lowertriangularsystem,canbesetupas,

1 0 0 d1 1
0 .3
1 0 d 2 0
0.1 0.148148 1 d 3 0

andsolvedwithforwardsubstitutionfor{d}T=[10.30.055556].Thisvectorcanthenbeusedas
therighthandsideoftheuppertriangularsystem,

10 2 1 x1 1
0 5 .4
1 .7 x 2 0 .3
0 0 5.351852 x3 0.055556

whichcanbesolvedbybacksubstitutionforthefirstcolumnofthematrixinverse,

0.110727 0 0
A 0.058824 0 0
1

0.010381 0 0

Todeterminethesecondcolumn,

1 0 0 d1 0
0 .3
1 0 d 2 1
0.1 0.148148 1 d 3 0

Thiscanbesolvedwithforwardsubstitutionfor{d}T=[100.148148],andtheresultsareused
withUtodetermine{x}bybacksubstitutiontogeneratethesecondcolumnofthematrixinverse,

0.110727 0.038062 0


A 0.058824 0.176471 0
1

0.010381 0.027682 0

Finally,thesameprocedurescanbeimplementedwith{b}T=[001]tosolvefor{d}T=[001],and
theresultsareusedwithUtodetermine{x} bybacksubstitutiontogeneratethethirdcolumnofthe
matrixinverse,

0.110727 0.038062 0.00692


A 1 0.058824 0.176471 0.058824
0.010381 0.027682 0.186851

Thisresultcanbecheckedbymultiplyingittimestheoriginalmatrixtogivetheindentitymatrix.
ThefollowingMATLABsessioncanbeusedtoimplementthischeck,

>>A=[1021;362;115];

>>AI=[0.1107270.0380620.00692;

0.0588240.1764710.058824;

0.0103810.0876820.186851];

>>A*AI

ans=

1.0000 0.0000 0.0000

0.0000 1.0000 0.0000

0.0000 0.0000 1.0000

PROBLEMS

(Ifnotmention,use3decimalplaces)

Problem1:

FromthegivenmatrixA,findmatricesLandU

4 2 3
A 3 1 4
2 4 5

Problem2:

FromthegivenmatrixA,findmatricesLandU

4 2 1 3
3 4 2 5
A
2 6 5 2

5 1 6 3

Problem3:

UseLUdecompositionwithpivotingtosolvethefollowinglinearsystem

2 4 1 x1 5
4 10 2 x 8
2
1 2 4 x3 13

Problem4:

Use(a)LUdecompositionand(b)GaussJordaneliminationtofindtheinverseofthematrix

4 8 4 0
1 4 7 2
A
1 5 4 3

1 3 0 2

TOPIC-05
EXAMPLES

Example1:(Problem11.1,Chapra)

(a)UsetheGaussSeidelmethodtosolvethefollowingsystemuntilthepercentrelative
errorfallsbelows=5%(initialguesses:x1,x2,x3=0)

0.8 0.4 X1 41
0.4 0.8 0.4 X 25
2
0. 4 0.8 X 3 105

(b)Repeat(a)butuseoverrelaxationwith=1.2.

Solution

(a)Thefirstiterationcanbeimplementedas

41 0.4x 2 41 0.40
x1 51.25
0.8 0.8

25 0.4x 1 0.4x 3 25 0.451.25 0.40


x2 56.875
0.8 0.8

105 0.4x 2 105 0.456.875


x3 159.6875
0.8 0.8

Seconditeration:

41 0.456.875
x1 79.6875
0.8

25 0.479.6875 0.4159.6875
x2 150.9375
0.8

105 0.4150.9375
x3 206.7188
0.8

Theerrorestimatescanbecomputedas

79.6875 51.25
a,1 100% 35.69%
79.6875

150.9375 56.875
a,2 100% 62.32%
150.9375

206.7188 159.6875
a,3 100% 22.75%
206.7188

Theremainderofthecalculationproceedsuntilallheerrorsfallbelowthestoppingcriterionof5%.
Theentirecomputationcanbesummarizedas


a a
iteration unknown value maximum

1 x1 51.25 100.00%

x2 56.875 100.00%

x3 159.6875 100.00% 100.00%

2 x1 79.6875 35.69%

x2 150.9375 62.32%

x3 206.7188 22.75% 62.32%

3 x1 126.7188 37.11%

x2 197.9688 23.76%

x3 230.2344 10.21% 37.11%

4 x1 150.2344 15.65%

x2 221.4844 10.62%

x3 241.9922 4.86% 15.65%

5 x1 161.9922 7.26%

x2 233.2422 5.04%

x3 247.8711 2.37% 7.26%

6 x1 167.8711 3.50%

x2 239.1211 2.46%

x3 250.8105 1.17% 3.50%

Thus,after6iterations,themaximumerroris3.5%andwearriveattheresult:

x1=167.8711,x2=239.1211andx3=250.8105.

(b)Thesamecomputationcanbedevelopedwithrelaxationwhere=1.2.

Firstiteration:

41 0.4x 2 41 0.40
x1 51.25
0.8 0.8

Relaxationyields:x1=1.2(51.25)0.2(0)=61.5

25 0.4x 1 0.4x 3 25 0.461.5 0.40


x2 62
0.8 0.8

Relaxationyields:x2=1.2(62)0.2(0)=74.4

105 0.4x 2 105 0.474.4


x3 168.45
0.8 0.8

Relaxationyields:x3=1.2(168.45)0.2(0)=202.14

Seconditeration:

41 0.474.4
x1 88.45
0.8

Relaxationyields:x1=1.2(88.45)0.2(61.5)=93.84

25 0.493.84 0.4202.14
x2 179.24
0.8

Relaxationyields:x2=1.2(179.24)0.2(74.4)=200.208

105 0.4200.208
x3 231.354
0.8

Relaxationyields:x3=1.2(231.354)0.2(202.14)=237.1968

Theerrorestimatescanbecomputedas

93.84 61.5
a,1 100% 34.46%
93.84

200.208 74.4
a,2 100% 62.84%
200.208

237.1968 202.14
a,3 100% 14.78%
237.1968

Theremainderofthecalculationproceedsuntilalltheerrorsfallbelowthestoppingcriterionof5%.
Theentirecomputationcanbesummarizedas


a a
iteration unknown value relaxation maximum

1 x1 51.25 61.5 100.00%

x2 62 74.4 100.00%

x3 168.45 202.14 100.00% 100.00%

2 x1 88.45 93.84 34.46%

x2 179.24 200.208 62.84%

x3 231.354 237.1968 14.78% 62.839%

3 x1 151.354 162.8568 42.38%

x2 231.2768 237.49056 15.70%

x3 249.99528 252.55498 6.08% 42.379%

4 x1 169.99528 169.99528 5.00%

x2 243.23898 243.23898 2.82%

x3 253.44433 253.44433 0.42% 4.997%

Thus,relaxationspeedsupconvergence.After6iterations,themaximumerroris4.997%,andwe
arriveattheresult:x1=171.423,x2=244.389andx3=253.622.

Example2:(Problem11.3,Chapra)

RepeatProb.11.2butuseJacobiiteration.

=>Problem11.2UsetheGaussSeidelmethodtosolvethefollowingsystemuntil
thepercentrelativeerrorfallsbelows=5%(initialguesses:x1,x2,x3=0)

10x1+2x2x3=27

3x16x2+2x3=61.5

x1+x2+5x3=21.5

Solution

Thefirstiterationcanbeimplementedas

27 2x 2 x 3 27 20
x1 2.7
10 10

61.5 3x 1 2x 3 61.5 30 20
x2 10.25
6 6

21.5 x1 x 2 21.5 0 0
x3 4.3
5 5

Seconditeration:

27 210.25 4.3
x1 0.22
10
61.5 32.7 2 4.3
x2 7.466667
6

21.5 2.7 10.25


x3 6.89
5

Theerrorestimatescanbecomputedas

0.22 2.7
a,1 100% 1127%
0.22

7.466667 10.25
a,2 100% 37.25%
7.466667

6.89 4.3
a,3 100% 37.59%
6.89

Theremainderofthecalculationproceedsuntilalltheerrorsfallbelowthestoppingcriterionof5%.
Theentirecomputationcanbesummarizedas


a a
iteration unknown value maximum

1 x1 2.7 100.00%

x2 10.25 100.00%

x3 4.3 100.00% 100.00%

2 x1 0.22 1127.27%

x2 7.466667 37.28%

x3 6.89 37.59% 1127.27%

3 x1 0.517667 57.50%

x2 7.843333 4.80%

x3 5.83733 18.03% 57.50%

4 x1 0.5476 5.47%

x2 8.045389 2.51%

x3 5.9722 2.26% 5.47%

5 x1 0.493702 10.92%

x2 7.985467 0.75%

x3 6.0186 0.77% 10.92%

6 x1 0.501047 1.47%

x2 7.99695 0.14%

x3 5.99583 0.38% 1.47%

Example3:(Problem11.1,Chapra)

Determinethesolutionofthesimultaneousnonlinearequations:

y=x2+x+0.5

y+5xy=x2

UsetheNewtonRaphsonmethodandemployinitialguessesofx=y=1.2.

Solution

Theequationstobesolvedare

f1 x, y x 2 x 0.5 y

f 2 x, y x 2 y 5xy

Thepartialderivativescanbecomputedandevaluatedattheinitialguesses

f1,0 f1,0
2x 1 21.2 1 1.4 1
x y

f 2,0 f 2,0
2x 5y 21.2 51.2 3.6 1 5x 1 51.2 7
x y

TheycanthenbeusedtocomputedthedeterminantoftheJacobianforthefirstiterationis1.4(
7)(1)(3.6)=6.2

Thevaluesofthefunctionscanbeevaluatedattheinitialguessesas

f1,0 1.2 2 1.2 0.5 1.2 0.94

f 2,0 1.2 2 51.2 1.2 1.2 6.96


To finish Newton-Rahson

To solve by Jacobi Iterative method


Thenweget:

0.94 3.6 6.96 1


x 1.2 1.26129
6.2

6.96 1.4 0.94 3.6


y 1.2 0.174194
6.2

Thecomputationcanberepeateduntilanacceptableaccuracyisobtained.Theresultsare
summarizedas


iteration x y a1 a2

0 1.2 1.2

1 1.26129 0.174194 4.859% 588.889%

2 1.234243 0.211619 2.191% 17.685%


3 1.233319 0.212245 0.075% 0.295%

4 1.233318 0.212245 0.000% 0.000%

PROBLEMS

(Ifnotmention,use3decimalplaces)

Problem1:

UseJacobiiterationtosolvethelinearsystem

7 2 1 2 x1 3
2
8 3 1 x2 2

1 0 5 2 x3 5

0 2 1 4 x4 4

Try10,20and30iterations.(initialguesses:x1,x2,x3,x4=0)

Problem2:

UseGaussSeideliterationtosolvethelinearsystem

7 2 1 2 x1 3
2
8 3 1 x2 2

1 0 5 2 x3 5

0 2 1 4 x4 4

Try10,20and30iterationswithinitialguesses:x1,x2,x3,x4=0.Comparethespeedofconvergence
withJacobiiteration(Problem1).

Problem3:

UsingtheJacobi,GaussSeidelandSOR(with=1.4)iterativemethodstosolvethe
followinglinearsystem.(initialguesses:x1,x2,x3,x4=0.5andthes=1%)

7 3 1 2 x1 1
3
8 1 4 x2 0

1 1 4 1 x3 3

2 4 1 6 x4 1

Problem4:

Findthesolutionoftheequations

f x1 , x2 x12 x22 8 x1 4 x2 11 0

f x1 , x2 x12 x22 20 x1 75 0

Bytakingthestartingpointasx1=2,x2=4)andthevalueofas105
TOPIC-06
EXAMPLES

Example1:(Problem12.5,Chapra)

Theaccelerationduetogravityatanaltitudeyabovethesurfaceoftheearthisgivenby

y,(m) 0 20,000 40,000 60,000 80,000

g,(m/s2) 9.8100 9.7487 9.6879 9.6278 9.5682

Uselinearregressiontocomputegaty=55,000m.

Solution

i xi yi xi2 xiyi
1 0 9.8100 0 0

2 20000 9.7487 4.0E+08 194974


3 40000 9.6879 1.6E+09 387516

4 60000 9.6278 3.6E+09 577668

5 80000 9.5682 6.4E+09 765456


200000 48.4426 1.2E+10 1925614

5(1,925,614) 200,000(48.4426)
a1 3.0225 10 6
5(1.2 1010 ) 200,000 2

48.4426 200,000
a0 3.0225 10 6 9.80942
5 5

Therefore,thelineofbestfitis(usingthenomenclatureoftheproblem)

g 9.80942 3.0225 10 6 y

Thevalueat55,000mcanthereforebecomputedas

g 9.80942 3.0225 10 6 (55,000) 9.6431825 m/s2

Example2:(Problem12.6,Chapra)

Thefollowingdatawasgatheredtodeterminetherelationshipbetweenpressureand
temperatureofafixedvolumeof1kgofnitrogen.Thevolumeis10m3.

T,C 20 0 20 40 50 70 100 120

p,N/m2 7500 8104 8700 9300 9620 10,200 11,200 11,700

EmploytheidealgaslawpV=nRTtodetermineRonthebasisofthisdata.Notethatforthelaw,T
mustbeexpressedinKelvins.

Solution

Regressiongives

p 8100.47 30.3164T 2
0.999



PV
R
T n

P
30.3164
T

1kg
n
28g/mole

10
R 30.3164 3 8.487
10 /28

Thisisclosetothestandardvalueof8.314J/gmole.

Example3:(Problem12.9,Chapra)

FitapowermodeltothedatafromTable12.1butusenaturallogarithmstoperformthe
transformation.

Table12.1Experimentaldataforforce(N)andvelocity(m/s)fromawindtunnel

v,m/s 10 20 30 40 50 60 70 80

F,N 25 70 380 550 610 1220 830 1450

Solution

Plotofforceversuswindvelocityforanobjectsuspendedinawindtunnel.

Thedatacanbetransformed,plottedandfitwithastraightline canbeusedboth
logandln

v,m/s F,N lnv lnF


10 25 2.302585 3.218875
20 70 2.995732 4.248495

30 380 3.401197 5.940171

40 550 3.688879 6.3.9918


50 610 3.912023 6.413459

60 1220 4.094345 7.106606


70 830 4.248495 6.721426
80 1450 4.382027 7.279319

Note: Fromtheabovefigure,thegraphisapowermodel.Althoughitisrecommendthatthebase
10logarithmshouldbeselectedforlinearizationofthepowermodel,bothbase10logarithmand
naturallogarithmcanbeemployedforlinearization.

Theleastsquaresfitis

lnF=1.9842(lnv)1.2941

Theexponentis1.9842andtheleadingcoefficientise1.2941=0.274137.Therefore,theResultisthe
sameaswhenweusedcommonorbase10logarithms:

F=0.274137v1.9842
PROBLEMS

(Ifnotmention,use3decimalplaces)

Problem1:

Uselinearregressiontofitthefollowingdatapoints:

i 1 2 3 4 5

xi 1 2 3 4 5

yi 0.7 2.2 2.8 4.4 4.9

Then,todeterminethecorrelationcoefficient(r).

Problem2:

Thevibrationamplitudeofamachine(xi)ismeasuredatdifferentinstantsoftime(ti)and
theresultsareasfollows:

i 1 2 3 4

ti(sec) 0 2 4 6

xi(mm) 5.0 3.7 2.7 2.0

Fitacurveoftheformx(t)=aebtusingthedatagiven.

Problem3:

ExperimentsconductedduringthemachiningofAISI4140steelwithfixedvaluesofdepthof
cutandfeedrateyieldedthefollowingresults:

Cuttingspeed,V(m/min) 160 180 200 220 240

Toollife,T(min) 7.0 5.5 5.0 3.5 2.0

Determinethetoollifeequation,VTa=b,whereaandbareconstants,usingthemethodofleast
squares.
TOPIC-07
EXAMPLES

Example2:(Problem14.1,Chapra)

Giventhedata:

x 1 2 2.5 3 4 5

f(x) 0 5 7 6.5 2 0

(a)Calculatef(3.4)usingNewtoninterpolatingpolynomialsoforder1through3.Choosethe
sequenceofthepointsforyourestimatestoattainthebestpossibleaccuracy.

(b)Repeat(a)butusetheLagrangepolynomial.

Solution

(a)Newtonpolynomial.Orderingofpoints:

x0=3 f(x0)=6.5
x1=4 f(x1)=2
x2=2.5 f(x2)=7
x3=5 f(x3)=0

Notethatbasedpurelyonthedistancefromtheunknown,thefourthpointwouldbe(2,5).
However,becauseitprovidesbetterbalanceandislocatedonlyalittlebitfartherfromthe
unknown,thepointat(5,0)ischosen.

Firstorder:

2 6.5
f1 3.4 6.5 3.4 3 6.5 4.53.4 3 4.7
43

Secondorder:
72
4.5
f 2 3.4 = 4.7 2.5 4 3.4 33.4 4
2.5 3

3.333333 4.5
= 4.7 3.4 33.4 4
2.5 3


= 4.7 2.3333333.4 33.4 4 5.259887

Thirdorder:

07
3.333333
5 2.5 2.333333
f 3 3.4 = 5.259887 54 3.4 33.4 43.4 2.5
53
2.8 3.333333
= 2.333333
5.259887 54 3.4 33.4 43.4 2.5
53

= 5.259887 0.5333333 2.333333 3.4 33.4 4 3.4 2.5 4.95152


53

(b)Lagrangepolynomial.

Firstorder:

3.4 4 3.4 3
f 1 3.4 6.5 2 4.7
34 43

Secondorder:

f 2 3.4
3.4 43.4 2.5 6.5 3.4 33.4 2.5 2 3.4 33.4 4 7 5.259887
3 43 2.5 4 34 2.5 2.5 32.5 4

Thirdorder:

f 3 3.4
3.4 43.4 2.53.4 5 6.5 3.4 33.4 2.53.4 5 2
3 43 2.53 5 4.34 2.54 5


3.4 33.4 43.4 5 7 3.4 33.4 43.4 2.5 0 4.95152
2.5 32.5 42.5 5 5 35 45 2.5
PROBLEMS

(Ifnotmention,use3decimalplaces)

Problem1:

Findingthef(0.15)byusingseveralLagrangepolynomialsofdegreen=1,2,and3forthe
functionf(x)=cos(x)overtheinterval[0,1]employingthe0.1equispacedpoints.Thencompare
theresultswiththeexactsolutions.

Problem2:

Findingthef(0.15)byusingNewtonpolynomialsofdegreen=1,2,and3forthe
functionf(x)=cos(x)overtheinterval[0,1]employingthe0.1equispacedpoints.Thencompare
theresultswiththeexactsolutions.

TOPIC-08
EXAMPLES

Example1:(Problem16.2,Chapra)

Evaluatethefollowingintegral:

(1 e
- 2x
)dx
0

(a) Analytically
(b) Singleapplicationofthetrapezoidalrule
(c) CompositetrapezoidalrulewithN=2and4
(d) SingleapplicationofSimpsons1/3rule
(e) CompositeSimpsons1/3rulewithN=4,and
(f) Simpsons3/8rule

Foreachofnumericalestimates(b)through(f),determinethepercentrelativeerrorbasedon(a)

Solution

(a)Theanalyticalsolutioncanbeevaluatedas

1 e dx x 0.5e
4
2x 2x 4
0 4 0.5e 24 0 0.5e 2 0 3.500167731
0

(b)Singleapplicationofthetrapezoidalrule

4 0 0 0.999665 1.99329 1 42.88%


2

(c)Compositetrapezoidalrule

N=2:

4 0 0 20.981684 0.999665 2.96303 1 15.35%


4

N=4:

4 0 0 20.86466 0.981684 0.99752 0.999665 3.3437 1 4.47%


8
(d)SingleapplicationofSimpsons1/3rule

4 0 0 40.981684 0.999665 3.28427 1 6.17%

(e)CompositeSimpsons1/3rule(N=4)

4 0 0 40.86466 0.99752 20.981684 0.999665 3.47059 1 0.84%


12

(f)Simpsons3/8rule.

1 3.19%
4 0 0 30.930517 0.995172 0.999665 3.388365
8

Example2:(Problem16.6,Chapra)

Evaluatethedoubleintegral:


2 4

(x 3y 2 xy 3 )dxdy
2

2 0

(a)Analytically

(b)UsingthecompositetrapezoidalrulewithN=2

(c)UsingsingleapplicationsofSimpsons1/3rule

For(b)and(c),computethepercentrelativeerror.

Solution

(a)Theintegralcanbeevaluatedanalyticallyas,

4
2 x3 3 x
2 3 3y x y 2 dy
2

2 43 3y 2 4 y 3 42 dy

2 3 2

2
21.33333 12y 2 8y 3dy

21.33333y 4y 3
2y 4
2
2

21.333332 42 22 21.33333 2 4 2 2 2 21.33333


3 4 3 4

(b)ThecompositetrapezoidalrulewithN=2canbeusedtheevaluatetheinnerintegralatthe
threeequispacedvaluesofy,

y 2 : 4 0 12 2 24 28 88
4

y 0: 4 0 0 24 16 24
4

y 2: 4 0 12 28 36 40
4
Thereresultscanthenbeintegratedinytoyield

2 2 88 224 40 0
4

Whichrepresentsapercentrelativeerrorof

21.33333 0
1 100% 100%
21.33333

Whichisnotverygood.

(c)SingleapplicationsofSimpsons1/3rulecanbeusedtheevaluatetheinnerintegralatthethree
equispacedvaluesofy,

y 2 : 4 0 12 4 24 28 90.66667
6

y 0:
4 0 0 44 16 21.33333
6

y 2:
4 0 12 48 36 37.33333
6

Thereresultscanthenbeintegratedinytoyield

2 2 90.66667 421.33333 37.33333 21.33333


6

whichrepresentsapercentrelativeerrorof

21.33333 21.33333
1 100% 0%
21.33333

whichisperfect

PROBLEMS

(Ifnotmention,use3decimalplaces)

Problem1:

UseNewtonCotesformula(Trapezoidalrule)toestimatetheintegraloff(x)=ex*sin(x)
over[1,3]withh=2/3

Problem2:

Computetheintegraloff(x)=sin(x)/xbetweenx=0andx=1usingSimpsons1/3rulewith
h=0.5andthenwithh=0.25.

Problem3:
3
dx
Computetheintegralof 1 x
0
2
withh=0.25usingthefollowingmethods

(a) Trapezoidalrule
(b) Simsons1/3rule
(c) Simsons3/8rule

Problem4:
4 3

xy
8 x 3 5 x 2 y dxdy withx=y=0.25usingthe
2
Computetheintegralof
y 1 x 1

Trapezoidalrule

TOPIC-09
EXAMPLES

Example1:(Problem18.2,Chapra)

Solvethefollowingproblemovertheintervalfromx=0to1usingastepsizeof0.25where
y(0)=1.Displayallyourresultsonthesamegraph.

dy
(1 2 x) y
dx

a)Analytically

b)UsingEulersmethod

c)UsingHeunsmethodwithoutthecorrector

d)UsingRalstonsmethod

e)UsingthefourthorderRKmethod

Solution

(a)Theanalyticalsolutioncanbederivedbytheseparationofvariables,

dy
y
1 2xdx

Theintegralscanbeevaluatedtogive,

2 y x x2 C

SubstitutingtheinitialconditionsyieldsC=2.Substitutingthisvalueandrearranginggives

2
x2 x 2
y
2

Someselectedvaluecanbecomputedas

x y

0 1

0.25 1.336914
0.5 1.890625
0.75 2.743164
14

(b)Eulersmethod:

f 0,1 1 20 1 1

y0.25 1 10.25 1.25

y0.5 y0.25 f 0.25,1.250.25

f 0.25,1.25 1 20.25 1.25 1.67705

y0.5 1.25 1.677050.25 1.66926

Theremainingstepscanbeimplementedandsummarizedas

x y dy/dx
0 1 1
0.25 1.25 1.67705

0.5 1.66926 2.584

0.75 2.31526 3.804


1 3.26626 5.42184
(c)Heunsmethod: RK,n=2

Predictor:

g 1 1 20 1 1

y0.25 1 10.25 1.25

g 2 1 20.25 1.25 1.6771

Equation:

1 1.6771
y0.25 1 0.25 1.33463
2

Theremainingstepscanbeimplementedandsummarizedas

x y g1 xe y e g2 dy/dx
0 1 1.0000 0.25 1.25 1.6771 1.3385
0.25 1.33463 1.7329 0.5 1.76785 2.6592 2.1961

0.5 1.88364 2.7449 0.75 2.56987 4.0077 3.3763


0.75 2.72772 4.1290 1 3.75996 5.8172 4.9731

1 3.97099

(d)Ralstonsmethod: RK,n=2 (a=a2=2/3)

Predictor:

g 1 1 20 1 1

y0.1875 1 10.1875 1.1875

g 2 1 20.1875 1.1875 1.49837


Equation:


1 21.49837
y0.25 1 0.25 1.33306
3

Theremainingstepscanbeimplementedandsummarizedas

x y dy/dx
0 1 1 0.1875 1.1875 1.49837 1.3322
0.25 1.33306 1.73187 0.4375 1.65779 2.41416 2.1867

0.5 1.87974 2.74208 0.6875 2.39388 3.67464 3.3638


0.75 2.72069 4.12363 0.9375 3.49387 5.37392 4.9572

1 3.95998


+1step
(e)RK4


x y g1 xm ym g2 xm ym g3 xe ye g4
1 0.125 1.32583 1.1657 1.34961 1.3374 1.73469 1.3476
0 1.0000 1.1250 0.125 0.25
0.25 1.3369
1.73436 0.375 1.5537 2.18133 0.375 1.6096 2.2202 0.5 1.8919 2.75096 2.2147

0.5 1.8906 2.74997 0.625 2.2343 3.36322 0.625 2.3110 3.42043 0.75 2.7457 4.14253 3.4100

0.75 2.7431 4.14056 0.875 3.2606 4.96574 0.875 3.3638 5.04368 1 4.0040 6.00299 5.0271

1 3.9998

X i X i 1
X m
2

Example2:(Problem18.7,Chapra)

SlovethefollowingpairofODEsovertheintervalfromt=0to0.4usingastepsizeof0.1.
Theinitialconditionsarey(0)=2andz(0)=4.Obtainyoursolutionwith(a)Eulersmethodand(b)
thefourthorderRKmethod.Displayyourresultsasaplot

dy
2 y 5ze - t
dt
dz yz 2

dt 2

Solution

(a)Eulersmethod:

t y z dy/dt dz/dt

0 2 4 16 16

0.1 3.6 2.4 3.658049 10.368

0.2 3.965805 1.3632 2.35114 3.68486

0.3 3.730691 0.994714 3.77687 1.84568

0.4 3.353004 0.810147 3.99072 1.10035

(b)4thorderRKmethod:

g 1,1 f 1 0,2,4 22 54e 0 16

24
2
g 1,2 f 0,2,4 16
2

y0.05 2 160.05 2.8

z0.05 4 160.05 3.2

g 2,1 f 1 0.05,2.8,3.2 22.8 53.2e 0.05 9.619671

2.83.2
2
g 2,2 f 2 0.05,2.8,3.2 14.336
2
y 0.05 2 9.6196710.05 2.480984

z 0.05 4 14.3360.05 3.2832

g 3,1 f 1 0.05,2.480984,3.2832 22.480984 53.2832 e 0.05 10.65342

g f 0.05,2.480984,3.2832 2.4809843.2832 13.3718


2

3, 2 2
2

y 0.1 2 10.653420.1 3.065342

z 0.1 4 13.37180.1 2.662824

g 4,1 f 1 0.1,3.065342,2.662824 23.065342 53.2832 e 0.1 5.916431

3.0653422.662824
2
g 4, 2 f 2 0.1,3.065342,2.662824

10.8676
2

Thegscanthenbeusedtocomputetheincrement

16 29.619671 10.65342 5.916431


1 10.41043
6

16 2 14.336 13.3718 10.8676


2 13.7139
6

Theseslopeestimatescanthenbeusedtomakethepredictionforthefirststep

y0.1 2 10.410430.1 3.041043

z0.1 4 13.71390.1 2.628615

Theremainingstepscanbetakeninasimilarfashionandtheresultssummarizedas

t y z

0 2 4

0.1 3.041043 2.628615


0.2 3.342571 1.845308
0.3 3.301983 1.410581
0.4 3.107758 1.149986

Aplotofthesevaluescanbedeveloped.

Example3:

ConsiderasimplysupportedbeamwithmodulusofelasticityE,momentafinertiaI,a
uniformloadw,andendtensionT(seefigurebelow).Ify(x)denotesthedeflectionateachpointxin
thebeam,theny(x)satisfiesthedifferentialequation:

y' ' T wx x L
y ,
1 y'
2

3/2
EI 2EI (A1)

withboundaryconditions:

y0 yL 0.

( y t ) 2 isnegligibleandtheequationsimplifiesto:

T wx x L
y'' y .
EI 2EI (A2)

Toplotthebeamdeflectionbyusingthefinitedifferencemethod(forL=4,w=2)

Solution

Afinitedifferenceequationisanequationobtainedfromadifferentialequationbyreplacingthe
variablesbytheirdiscreteversionsandderivativesbydifferenceformulas.

Firstwewillconsiderequation(A2).SupposethatL=4,w=2andtheotherconstantsare1.Thus
wehavethefollowingBVP:

y' ' y x x 4 , y0 y4 0. (A3)

Wewillbeginbysubdividingtheinterval[0,4]intofourequalsubintervalsandcalltheendpointsof
thesubintervalsnodes.Wewillthendenotethenodesofthissubdivionbyx0=0,x1=1,,x4=4.
Wewillthenlety0,y1,,y4denotethedeflectionsatthenodes.Fromtheboundaryconditionswe
haveimmediately:

y0=y4=0.

Todeterminethedeflectionsattheinteriorpointswewillrelyonthedifferentialequation.Recall
thecentraldifferenceformula:

y i 1 2y i y i 1
y' ' x i .
h2

Inthiscasewehaveh=(ba)/n=1.Replacingallthevariablesintheequationbytheirdiscrete
versionsweget:

y i 1 2y i y i 1 y i x i x i 4.

Thisequationmakessensefori=1,2,3.Atx1=1,theequationbecomes:

y 2 2y1 y0 y1 11 4 or (A4)

y 2 3y1 3.

Notethatthisequationislinearintheunknownsy1andy2.Atx2=2wehave:

y 3 2y 2 y1 y 2 22 4
or (A5)

y 3 3y 2 y1 4.

Atx3=3:

y 4 2y y 3 33 4
3 y2 or (A6)

3y 3 y 2 3.

Thus(y1,y2,y3)isthesolutionofthelinearsystem:

3 1 0 3

1 3 1 4
0 1 3 3

WecaneasilyfindthesolutionofthissysteminMATLAB:

>A=[310;131;013]

>b=[343]

>y=A\b

Tographthesolution,weneedtoaddontheendpointsanddefinethexvalues:

>x=0:1:4

>y=[0;y;0]

>plot(x,y,*)

Addingasplinewillresultinanexcellentgraph.

TheexactsolutionofthisBVPis:

yx .036e 1.964e
x

x
x2 4x 2. (A7)

Wecanplotthetruesolutiononthesamegraph:

>holdon

>xx=0:.1:4;
>yy=(.036*exp(xx)+1.964*exp(xx)xx.^2+4*xx2);

>plot(xx,yy,green)

Themaximumdeflectionofthetruesolutionisy(2)=2.5318.Thusournumericalsolutionis
extremelygood,consideringhowfewsubintervalsweusedandhowlargethedeflectionis.

Example4:

d2y dy
Solvingthefollowingequation 2
y 0 wherey(0)=1and (1) 0 byusingx=0.25
dx dx
(theni=0to4).

Solution

d2y
y 0
dx 2

becomes

yi 1 2 yi yi 1
yi 0
h2

or


yi 1 2 h 2 yi yi 1 0

Thedifferenceequationatthelastpointis

yi 1 yi 1 then
2 yi 1 2 h 2 yi 0

Then

1 0 0 0 0 y 0 1

1 2 h 2 1 0 0 y 0
1
0 1
2h 2
1 0 y 2 0

0 0 1
2 h2 1

y 3 0
0 0 0 2 2

2 h y 4 0
PROBLEMS

(Ifnotmention,use3decimalplaces)

Problem1:

SolvetheI.V.P. y 1 ty withy(0)=1over 0 t 5 (t=1)using

a)UsingEulersmethod

b)UsingHeunsmethodwithoutthecorrector

c)UsingRalstonsmethod

d)UsingthefourthorderRKmethod

Problem2:

SolvetheI.V.P. y 1 t 3 y withy(0)=1over 0 t 5 (t=1)using

a)UsingEulersmethod

b)UsingHeunsmethodwithoutthecorrector

c)UsingRalstonsmethod

d)UsingthefourthorderRKmethod

Problem3:

SolvetheB.V.P.x=xwithx(0)=3andx()=7(t=/10)

Problem4:

SolvetheB.V.P.y=yt+tywithy(0)=1andy(1)=3(t=0.2)

Problem5:

SolvetheB.V.P.u=ut+tuwithu(0)=1andu(1)=0(t=0.2)

Problem6:

SolvetheB.V.P.v=vt+tvwithv(0)=1andv(1)=0(t=0.2)