You are on page 1of 2

BonusAssignmentENGR391Summer2013

Youhavetosolvetwoproblemsusingacomputerandnumericaltechniques.

Onefromeither7.22and7.23,andonefromeither8.25and8.26.Fromthetextbook.

(forexampleyoucouldsolveboth7.22and8.25)
7.22)WriteauserdefinedMATLABfunctionthatusesSimpsons3/8rulemethodforintegratinga
functionf(x)thisisgiveninanalyticalform(equation).Forthefunctionnameandargumentsuse
I=Simpson38(Fun,a,b).Funisanameforthefunctionbeingintegrated.Itisadummyforthefunction
thatisimportedintoSimposon38.Theactualfunctionthatisintegratedshouldbewrittenasan
anonymousoruserdefinedfunctionthatcalculates,usingelementbyelementoperations,thevaluesof
f(x)forgivenvaluesofx.ItisenteredasafunctionhandlewhenSimpson38isused.Thetermsaand
barethelimitsofintegration,andIisthevalueoftheintegral.Theintegrationfunctioncalculates
thevalueoftheintegraliniterations.Inthefirstinterval[a,b]isdividedintothreesubintervals.Ineach
iterationthatfollowsthenumberofintervalsdoubles.Theiterationsstopwhenthedifferenceinthe
valueoftheintegralbetweentwosuccessiveiterationsissmallerthan0.1%.
FunctionstoIntegrateare:I = ] cos
3
(x)Jx
3n
2
n
2
andI = ]
1
1+9x
2
1.2
-1.2
Jx.
7.23)WriteauserdefinedMATLABfunctionforintegrationofafunctionf(x)inthedomain[1,1]
j] (x)Jx
1
-1
[withfourpointGaussquadrature.Forthefunctionnameandargumentsuse:
I=GuassQuad4(Fun),whereFunisanameforthefunctionbeingintegrated.Itisadummynamefora
functionthatisimportedintoGaussQuad4.Theactualfunctionthatisintegratedshouldbewrittenas
ananonymousoruserdefinedfunctionthatcalculatesthevalueoff(x)foragivenvalueofx.Itis
enteredasafunctionhandlewhenGaussQuad4isused.TheoutputargumentIisthevalueofthe
integral.Usingthisfunctionsolve:I = ] 1 - 4x
2
Jx
0.5
-0.5
.Comparetheresultstothetruevaluediscuss
anydifferences.
8.25)WriteauserdefinedMATLABfunctionthatsolvesafirstorderODEbyapplyingtheclassicalthird
orderRungeKuttamethod.Usethefunctionyouhavedevelopedtosolve:
d
dt
= Su - 2.S - u.u1S
3
,
wherephiisthemagneticfluxinkilolines1 kilo - linc = 1u
-5
1
m
2
andtisthetimeinmilliseconds.
Findthemagneticfluxatt=0.5secondsiftheinitialvalueofthefluxiszero.
ComparetheresultsfromyourfunctiontothatofabuiltinMATLABOdesolver.
8.26)WriteauserdefinedMATLABfunctionthatsolvesafirstorderODEbyapplyingthefourthorder
RungeKuttamethod(codefoundonpages376377oftext).Usethefunctionyouhavedevelopedto
solve:
dh
dt
= -
0.02
2
2(9.81)h
8h-h
2
,whereh=6.5whent=0.Computethetimeforhtodecreasetoh=0.5.
ComparetheresultsofyourcodestotheanswerprovidedbyaMATLABbuiltinODEsolver.
Youshouldsubmitboththecodeandtheoutputofthesolution.Yourname,idandreferencesshould
beinthesubmittedassignment.

You might also like