东南大学Matlab作业1.docx
《东南大学Matlab作业1.docx》由会员分享,可在线阅读,更多相关《东南大学Matlab作业1.docx(56页珍藏版)》请在冰豆网上搜索。
东南大学Matlab作业1
MatlabWorksheet1
PartA
1.GetintoMatlab:
Usethediarycommandtorecordyouractivityintoafile:
diarymydiary01.docbeforeyoustartyourwork.(Anddiaryofftoswitchoffyourdiarywhenyoufinishyourwork.)
AttheCommandWindowassignavaluex=10,thenusetheUpKey↑torepeattheexpression,editingittoshowtheeffectofusingasemicolonafterthe10,namelyx=10;
Answers:
>>x=10
x=
10
>>x=10;
2.Confirmwhetherthefollowingnamesofvariablesareacceptable:
a)VelocityYesNo
b)Velocity1YesNo
c)Velocity.1YesNo
d)Velocity_1YesNo
e)Velocity-01YesNo
f)velocityONEYesNo
g)1velocityYesNo
Answers:
(1)legalvariablenames:
a)Velocity
b)Velocity1
d)Velocity_1
f)velocityONE
(2)illegalvariablenames:
c)Velocity.1
e)Velocity-01
g)1velocity
3.Assigntwoscalarvariablesxandyvaluesx=1.5,y=2.3,thenconstructMatlabexpressionsforthefollowing:
a)
b)
c)
d)
Answers:
theresultoftheCommandWindowis:
>>x=1.5;y=2.3;
z1=5*x^3*y/(x+y)
z2=(x^7*y^0.5)^(2/3)
z3=(x^(1/6)/(log10(x^5-1))+1)*exp(-2*y)
z4=sin(2*pi*x-y)+exp(x).*cos(2*pi*x)
z1=
10.2138
z2=
8.7566
z3=
0.0232
z4=
-3.7360
4.Assigntwovariableswithcomplexvaluesu=2+3jandv=4+10jandthenconstructexpressionfor:
a)
b)
c)
d)
Answers:
theresultoftheCommandWindowis:
>>u=2+3j;v=4+10j;
z1=u/v
z2=u*v+2j
z3=u/2j
z4=v*exp(-j*2*pi*u)
z1=
0.3276-0.0690i
z2=
-22.0000+34.0000i
z3=
1.5000-1.0000i
z4=
6.1421e+08+1.5355e+09i
5.Usethecolonoperator:
toassignnumericalvaluesbetween0and1tovectorarrayvariableainstepsof0.1.
Answer:
theresultoftheCommandWindowis:
>>V=0:
0.1:
1
V=
Columns1through10
00.10000.20000.30000.40000.50000.60000.70000.80000.9000
Column11
1.0000
6.Uselinspacefunctiontoassign20valuestovectorvariableybetween20and30.
Answer:
theresultoftheCommandWindowis:
>>V=linspace(20,30,20)
V=
Columns1through10
20.000020.526321.052621.578922.105322.631623.157923.684224.210524.7368
Columns11through20
25.263225.789526.315826.842127.368427.894728.421128.947429.473730.0000
7.Assign20valuestoavariablehincreasinglogarithmicallybetween10and1000.
Next,usethecolonoperatortoassignthefirst10elementsofhtoavariablep.
Answers:
>>v=logspace(1,3,20)
v=
1.0e+03*
Columns1through10
0.01000.01270.01620.02070.02640.03360.04280.05460.06950.0886
Columns11through20
0.11290.14380.18330.23360.29760.37930.48330.61580.78481.0000
>>p=v(1:
10)
p=
10.000012.742716.237820.691426.366533.598242.813354.555969.519388.5867
8.Create6elementrowvectorzwithvalues1.01.21.6-1.71.81.9,thenconstructanexpressionforthesumofthe2nd4thand6thelementsofz.
Answers:
>>z=[1.01.21.6-1.71.81.9]
x=z
(2)+z(4)+z(6)
z=
1.00001.20001.6000-1.70001.80001.9000
x=
1.4000
9.Usethecolonoperatortocreateavectorarrayxbetween10and-10instepsof-1,andsecond,anarrayvectorybetween20and-20insteps-2.
a)Addxandy,b)subtract10xfrom5y.
Answers:
>>x=10:
-1:
-10
y=20:
-2:
-20
x=
Columns1through17
109876543210-1-2-3-4-5-6
Columns18through21
-7-8-9-10
y=
Columns1through17
20181614121086420-2-4-6-8-10-12
Columns18through21
-14-16-18-20
>>x+y
ans=
Columns1through17
302724211815129630-3-6-9-12-15-18
Columns18through21
-21-24-27-30
>>5*y-10*x
ans=
Columns1through17
00000000000000000
Columns18through21
0000
10.Usethesize,length,whoandwhoscommandstoestablishthesizeandlengthofxandyfromQuestion9,andusetransposeoperator’toconvertvectorxfromQuestion9.
Answers:
>>size(x)
length(x)
ans=
121
ans=
21
>>who
Yourvariablesare:
ansxy
>>whos
NameSizeBytesClassAttributes
ans1x18double
x1x21168double
y1x21168double
>>z=x'
z=
10
9
8
7
6
5
4
3
2
1
0
-1
-2
-3
-4
-5
-6
-7
-8
-9
-10
11.Showthatifw=[2i3i3+i]the.’operatorcreatesthetranspose.Whateffectdoestheoperator’appliedtowhaveonitsown?
Answer:
>>w=[2i3i3+i]
w=
0+2.0000i0+3.0000i3.0000+1.0000i
>>x=w'
x=
0-2.0000i
0-3.0000i
3.0000-1.0000i
>>y=w.'
y=
0+2.0000i
0+3.0000i
3.0000+1.0000i
12.Usetheonesfunctiontocreatea4by6arrayof1’s.Consideringjusttheshapeoftheresultingarray,whatdotheexpressionones(3),ones(5)andones(7)allhaveincommon?
Answer:
>>v=ones(4,6)
v=
111111
111111
111111
111111
>>ones(3)
ans=
111
111
111
>>ones(5)
ans=
11111
11111
11111
11111
11111
Ones(n)是n阶全为1的方阵
13.Createusingtherandfunctiona5by4randommatrixandassignittomatrixarrayvariableAandobservecarefullywhatA(:
3)A(1:
2)andA(3,[24])mean.
Answer:
>>A=rand(5,4)
A=
0.81470.09750.15760.1419
0.90580.27850.97060.4218
0.12700.54690.95720.9157
0.91340.95750.48540.7922
0.63240.96490.80030.9595
>>A(:
3)
ans=
0.1576
0.9706
0.9572
0.4854
0.8003
>>A(1:
2)
ans=
0.81470.9058
>>A(3,[24])
ans=
0.54690.9157
14.Usingarraysubscripts,createanexpressionforthesumoftheelementinthetopright-hand-cornerofAandthebottomleft-hand-cornerofA.Alsoassignthe2ndcolumnofAtoacolumnvectorb,andassignthe3rdrowofAtoarowvectord.
Answer:
>>A=rand(5,4)
A=
0.75130.95930.84070.3500
0.25510.54720.25430.1966
0.50600.13860.81430.2511
0.69910.14930.24350.6160
0.89090.25750.92930.4733
>>x=A(1,4)+A(4,1)
x=
1.0491
>>b=A(:
2)
b=
0.9593
0.5472
0.1386
0.1493
0.2575
>>d=A(3,:
)
d=
0.50600.13860.81430.2511
>>diaryofftoswitchoffyourdiarynow.
15.Usingthecolonoperator,assignarowvectorarrayt,valuesbetween0and10instepsof0.01.Usethe;operatortopreventdisplayingtheinformation.Obtaintheterm-by-termvaluesoffunctions:
a)
b)
c)
Answers:
(1)home_work_1_A_15.m
t=0:
0.01:
10;
z1=exp(-0.05*t)
z2=z1.*sin(pi*t)
z3=z2.*cos(2*pi*t)
(2)result
>>home_work_1_A_15
z1=
Columns1through10
1.00000.99950.99900.99850.99800.99750.99700.99650.99600.9955
Columns11through20
0.99500.99450.99400.99350.99300.99250.99200.99150.99100.9905
Columns21through30
0.99000.98960.98910.98860.98810.98760.98710.98660.98610.9856
Columns31through40
0.98510.98460.98410.98360.98310.98270.98220.98170.98120.9807
Columns41through50
0.98020.97970.97920.97870.97820.97780.97730.97680.97630.9758
Columns51through60
0.97530.97480.97430.97380.97340.97290.97240.97190.97140.9709
Columns61through70
0.97040.97000.96950.96900.96850.96800.96750.96710.96660.9661
Columns71through80
0.96560.96510.96460.96420.96370.96320.96270.96220.96180.9613
Columns81through90
0.96080.96030.95980.95930.95890.95840.95790.95740.95700.9565
Columns91through100
0.95600.95550.95500.95460.95410.95360.95310.95270.95220.9517
Columns101through110
0.95120.95080.95030.94980.94930.94890.94840.94790.94740.9470
Columns111through120
0.94650.94600.94550.94510.94460.94410.94360.94320.94270.9422
Columns121through130
0.94180.94130.94080.94040.93990.93940.93890.93850.93800.9375
Columns131through140
0.93710.93660.93610.93570.93520.93470.93430.93380.93330.9329
Columns141through150
0.93240.93190.93150.93100.93050.93010.92960.92910.92870.9282
Columns151through160
0.92770.92730.92680.92640.92590.92540.92500.92450.92400.9236
Columns161through170
0.92310.92270.92220.92170.92130.92080.92040.91990.91940.9190
Columns171through180
0.91850.91810.91760.91710.91670.91620.91580.91530.91480.9144
Columns181through190
0.91390.91350.91300.91260.91210.91160.91120.91070.91030.9098
Columns191through200
0.90940.90890.90850.90800.90760.90710.90660.90620.90570.9053
Columns201through210
0.90480.90440.90390.90350.90300.90260.90210.90170.90120.9008
Columns211through220
0.90030.89990.89940.89900.89850.89810.89760.89720.89670.8963
Columns221through230
0.89580.89540.89490.89450.89400.89360.89320.89270.89230.8918
Columns231through240
0.89140.89090.89050.89000.88960.88910.88870.88830.88780.8874
Columns241through250
0.88690.88650.88600.88560.88510.88470.88430.88380.88340.8829
Columns251through260
0.88250.88210.88160.88120.88070.88030.87990.87940.87900.8785
Columns261through270
0.87810.87770.87720.87680.87630.87590.87550.87500.87460.8742
Columns271through280
0.87370.87330.87280.87240.87200.87150.87110.87070.87020.8698
Columns281through290
0.86940.86890.86850.86810.86760.86720.86680.86630.86590.8655
Columns291through300
0.86500.86460.86420.86370.86330.86290.86240.86200.86160.8611
Columns301through310
0.86070.86030.85980.85940.85900.85860.85810.85770.85730.8568
Columns311through320
0.85640.85600.85560.85510.85470.85430.85380.85340.85300.8526
Columns321through330
0.85210.85170.85130.85090.85040.85000.84960.84920.84870.8483
Columns331through340
0.84790.84750.84700.84660.84620.84580.84540.84490.84450.8441
Columns341through350
0.84370.84320.84280.84240.84200.84160.84110.84070.84030.8399
Columns351through360
0.83950.83900.83860.83820.83780.83740.83690.83650.8