Vous êtes sur la page 1sur 2

CMPSC200Homework8Assigned12/3/2014Due11:59p.m.

ESTon12/12/2014

Submithomeworkbysendingmeazipfileofallyour.mfilesasanemailattachmenttomae102@psu.edu.
YoudonotneedtosendthisviaANGELyoucanuseanyemailsystem.Thezipfilenameshouldinclude
yournameandHW8e.g.,JulianAssangeHW8.zip.Iwillrunyourprogramandgradeyouonthecode,the
promptsforinput,andtheprogramoutput.

Pointswillbetakenoffforincorrectfilename,nothavingyouranswersprintout(includingtextualanswers),
printingoutmorethanjustanswers,etc.

1. Dontforget,inthe.mfile,dothefollowing.
a. ClearallinputandoutputfromtheCommandWindow(CW)displaybyenteringclcandall
variablesbyenteringclear
b. Enterthefollowingcommandstohavethecoursename,assignmentname,yourname,and
youremailaddressprinted,e.g.,
i.
fprintf(\nCMPSC200Homework8\n)
ii.
fprintf(Assange,Julian<b_r499@psu.edu>\n\n)
c. Ishouldbeabletoloadyour.mfile,runit,respondtoanypromptsforinput,andseeyour
output.
2. Solve2x2SystemofLinearEquations
a. Writeascriptthatwillsolvea2x2systemoflinearequationswithallcoefficientsbeingreal.
b. Prompttheuserforthecoefficientsandthevalueoftheequation...clearlystatewhatyouare
askingtheusertoinput.UsegetAndCheck.mtoverifytheinput.Theleftsideofthe
equations,i.e.,thecoefficients,mustbeplacedinmatrixA(2x2),andtherightsideofthe
equations,i.e.,theresultsoroutputsoftheequations,mustbeplacedinmatrixB(2x1).
c. UsetheGaussJordanmethodtosolvethesystemoflinearequations.
d. Createafunction,normalize.m,towhichyoucanpassanequationandtheindexofthe
coefficientyouareattemptingtonormalizeandreceivebackamodifiedversionofthepassed
equationthathasthespecifiedcoefficientnormalized.
e. Createafunction,replace.m,towhichyoucanpassanequationinwhichyouareattempting
toeliminateavariable(i.e.,achieveavalueofzeroforaparticularcoefficient)anda
previouslynormalizedequationandreceivebackamodifiedversionofthepassedequationin
whichyouwereattemptingtoeliminatesaidvariable.
f. CompareandbythisImeanhavethecomputercompareyoursolutionwithMATLABs
solutionwiththelinsolvefunction.
3. SolveanxnSystemofLinearEquations
a. Writeascriptthatwillsolveanxnsystemoflinearequationswithallcoefficientsbeingreal
andnrangingfrom2to9.
b. Createafunction,getEquations.m,toprompttheuserfornandthensuccessively(viaforor
whileloops)populatetheAandBarrays.UsegetAndCheck.mtoverifytheinput.
c. Callviafororwhileloopsthepreviouslydevelopednormalizeandreplacefunctionsthe
appropriatenumberoftimesbasedonthevalueofn.
d. CompareandbythisImeanhavethecomputercompareyoursolutionwithMATLABs
solutionwiththelinsolvefunction.
e. Usethesetsofequationsonthenextpagetoverifyyourprogram.


Herearesomesampleequationsyoucanusetoverifyyourprogram.
1. Firstsetofequations

2x1+x2+x3+2x4=2
4x1+4x2+x3+2x4=4
6x1+x2+10x3+2x4=5
2x1+x2+8x3+2x4=1

2. Secondsetofequations

475x1+316x2+407x3+253x4=521
291x1+482x2+395x3+242x4=720
364x1+421x2+643x3+342x4=634
282x1+286x2+315x3+448x4=266

3. Thirdsetofequations

2x1+2x2+4x3=12
2x1+3x2+2x3=8
x1+x2+x3=3.5

4. Fourthsetofequations

8x1+2x2+x3=1
2x1+8x2+2x3+x4=1
x1+2x2+8x3+2x4+x5=1
x2+2x3+8x4+2x5=1
x3+2x4+8x5=1

Vous aimerez peut-être aussi