Professional Documents
Culture Documents
. .
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:
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:
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
0.5 0
xr 0.25
2
Therefore,therootisinthesecondintervalandthelowerguessisredefinedasx1=0.5.The
seconditerationis
(c)Usingfalseposition,thefirstiterationis
12 1 0
xr 0 0.28725
29.75 12
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
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
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|
(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
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
Forthethirdrow(i=3),
Thus,theCholeskydecompositionyields
(b)
>>A=[82015;208050;1560];
>>U=chol(A)
U=
(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,
Thisresultcanbecheckedbymultiplyingittimestheoriginalmatrixtogivetheindentitymatrix.
ThefollowingMATLABsessioncanbeusedtoimplementthischeck,
>>A=[1021;362;115];
>>AI=[0.1107270.0380620.00692;
0.0588240.1764710.058824;
0.0103810.0876820.186851];
>>A*AI
ans=
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
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%
2 x1 79.6875 35.69%
x2 150.9375 62.32%
3 x1 126.7188 37.11%
x2 197.9688 23.76%
4 x1 150.2344 15.65%
x2 221.4844 10.62%
5 x1 161.9922 7.26%
x2 233.2422 5.04%
6 x1 167.8711 3.50%
x2 239.1211 2.46%
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
Relaxationyields:x2=1.2(62)0.2(0)=74.4
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
x2 62 74.4 100.00%
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
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%
2 x1 0.22 1127.27%
x2 7.466667 37.28%
3 x1 0.517667 57.50%
x2 7.843333 4.80%
4 x1 0.5476 5.47%
x2 8.045389 2.51%
5 x1 0.493702 10.92%
x2 7.985467 0.75%
6 x1 0.501047 1.47%
x2 7.99695 0.14%
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
Thecomputationcanberepeateduntilanacceptableaccuracyisobtained.Theresultsare
summarizedas
iteration x y a1 a2
0 1.2 1.2
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
Uselinearregressiontocomputegaty=55,000m.
Solution
i xi yi xi2 xiyi
1 0 9.8100 0 0
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
Example2:(Problem12.6,Chapra)
Thefollowingdatawasgatheredtodeterminetherelationshipbetweenpressureand
temperatureofafixedvolumeof1kgofnitrogen.Thevolumeis10m3.
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
Solution
Plotofforceversuswindvelocityforanobjectsuspendedinawindtunnel.
Thedatacanbetransformed,plottedandfitwithastraightline canbeusedboth
logandln
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
Then,todeterminethecorrelationcoefficient(r).
Problem2:
Thevibrationamplitudeofamachine(xi)ismeasuredatdifferentinstantsoftime(ti)and
theresultsareasfollows:
i 1 2 3 4
ti(sec) 0 2 4 6
Fitacurveoftheformx(t)=aebtusingthedatagiven.
Problem3:
ExperimentsconductedduringthemachiningofAISI4140steelwithfixedvaluesofdepthof
cutandfeedrateyieldedthefollowingresults:
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
(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
(c)Compositetrapezoidalrule
N=2:
N=4:
(e)CompositeSimpsons1/3rule(N=4)
(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
(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
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
Theremainingstepscanbeimplementedandsummarizedas
x y dy/dx
0 1 1
0.25 1.25 1.67705
Predictor:
g 1 1 20 1 1
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
1 3.97099
Predictor:
g 1 1 20 1 1
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
+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
(b)4thorderRKmethod:
24
2
g 1,2 f 0,2,4 16
2
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
3, 2 2
2
3.0653422.662824
2
g 4, 2 f 2 0.1,3.065342,2.662824
10.8676
2
Thegscanthenbeusedtocomputetheincrement
Theseslopeestimatescanthenbeusedtomakethepredictionforthefirststep
Theremainingstepscanbetakeninasimilarfashionandtheresultssummarizedas
t y z
0 2 4
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:
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:
a)UsingEulersmethod
b)UsingHeunsmethodwithoutthecorrector
c)UsingRalstonsmethod
d)UsingthefourthorderRKmethod
Problem2:
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)