MATLAB 程序设计教程第二版实验答案包括第七章.docx
《MATLAB 程序设计教程第二版实验答案包括第七章.docx》由会员分享,可在线阅读,更多相关《MATLAB 程序设计教程第二版实验答案包括第七章.docx(13页珍藏版)》请在冰点文库上搜索。
![MATLAB 程序设计教程第二版实验答案包括第七章.docx](https://file1.bingdoc.com/fileroot1/2023-5/4/0a977f16-7b2a-4ead-aff6-36551dd0bd64/0a977f16-7b2a-4ead-aff6-36551dd0bd641.gif)
MATLAB程序设计教程第二版实验答案包括第七章
MATLAB
第二章:
1.
(1)w=sqrt
(2)*(1+0.34245*10^(-6))
w=
1.4142
(2)a=3.5;
b=5;
c=-9.8;
x=(2*pi*a+(b+c)/(pi+a*b*c)-exp
(2))/(tan(b+c)+a)
x=
0.9829
(3)a=3.32;
b=-7.9;
y=2*pi*a^2*((1-pi/4)*b-(0.8333-pi/4)*a)
y=
-128.4271
(4)t=[2,1-3i;5,-0.65];
>>z=0.5*exp(2*t)*log(t+sqrt(1+t*t))
z=
1.0e+004*
0.0057-0.0007i0.0049-0.0027i
1.9884-0.3696i1.7706-1.0539i
2
A=[-1,5,-4;0,7,8;3,61,7];B=[8,3,-1;2,5,3;-3,2,0];
>>
(1)A+6*B
ans=
4723-10
123726
-15737
>>A^2-B+eye
ans=
-18-21618
23533110
22868526
>>
(2)A*B
ans=
141416
-105121
125328180
>>A.*B
ans=
-8154
03524
-91220
>>B*A
ans=
-110-15
722853
3-128
(3)A/B
ans=
1.2234-0.92552.9787
-0.94682.3511-0.9574
4.61703.872313.8936
>>B\A
ans=
-0.5106-8.6170-1.1277
0.734017.57451.8085
-0.8830-21.21280.4043
>>(4)[A,B]
ans=
-15-483-1
078253
3617-320
>>[A([1,3],:
);B^2]
ans=
-15-4
3617
73371
173713
-2019
>>3
A=[23,10,-0.778,0;41,-45,65,5;32,5,0,32;6,-9.54,54,3.14];
(1)b=find(A>=10&A<=25);
>>A(b)
ans=
23
10
(2)B=A(1:
3,:
)
B=
23.000010.0000-0.77800
41.0000-45.000065.00005.0000
32.00005.0000032.0000
C=A(:
1:
2)
C=
23.000010.0000
41.0000-45.0000
32.00005.0000
6.0000-9.5400
>>D=A(2:
4,3:
4)
D=
65.00005.0000
032.0000
54.00003.1400
>>E=B*C
E=
1.0e+003*
0.9141-0.2239
1.20802.7123
1.1330-0.2103
(3)Eans=
01
00
01
>>E&D
ans=
11
01
11
>>E|D
ans=
11
11
11
~E|~D
ans=
00
10
00
第三章:
2.
(1)
c=input('请输入成绩');
if(c>=90&c<=100)
disp'A';
elseif(c>=80)
disp'B';
elseif(c>=70)
disp'C';
elseif(c>60)
disp'D';
else
disp'E';
end
请输入成绩55
E
c=input('pleaseenter:
');
switchfix(c/10)
case{9,10}
disp('A');
case{8}
disp('B');
case{7}
disp('C');
case{6}
disp('D');
case{0,1,2,3,4,5}
disp('E');
end
>>as
pleaseenter:
55
E
>>as
pleaseenter:
67
D
(2)
while
(1)
c=input('请输入成绩');
if(c>=90&c<=100)
disp'A';
elseif(c<90&c>=80)
disp'B';
elseif(c<80&c>=70)
disp'C';
elseif(c<70&c>=60)
disp'D';
elseif(c<60&c>=0)
disp'E';
else
disp'wrong'
end
end
>>third
请输入成绩113
wrong
请输入成绩-47
wrong
请输入成绩45
E
请输入成绩89
B
请输入成绩78
C
3.
a=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
b=max(a)
c=min(a)
b=0
c=0
fori=1:
20
ifa(i)>b
b=a(i);
end
ifa(i)c=a(i);
end
end
b
c
6.
A=rand(5,6)
n=input('请输入矩阵:
');
ifn>5
n=5
A(n,n)
else
A(n)
End
6.a=rand(5,6);
n=input('请输入n');
ifn==1
disp(a(1,:
))
end
ifn==2
disp(a(2,:
))
end
ifn==3
disp(a(3,:
))
end
ifn==4
disp(a(4,:
))
end
ifn==5
disp(a(5,:
))
end
ifn>5
disp(a(5,:
))
end
第四章:
1.
(1)
x=-12:
0.001:
12;
y=x-x.^3/6;
plot(x,y);
xlabel('x轴');
ylabel('y轴');
title('Y=X-X^3/3!
');
(2)
ezplot('x^2+2*y^2-64',[-8,8,-8,8])
xlabel('x轴');
ylabel('y轴');
axisequal
title('x^2+2y^2=64');
4.
(1)
t=0:
pi/100:
2*pi;
x=exp(-t/20).*cos(t);
y=exp(-t/20).*sin(t);
z=t;
plot3(x,y,z)
(2)
[x,y]=meshgrid(-5:
5);
z=ones(11);
surf(x,y,z);shadinginterp;
第五章
1.
(1)
A=randn(10,5);
a=mean(A)
a=
0.00130.23100.02530.3588-0.4197
b=std(A)
b=
0.90340.88291.18980.78321.0821
(2)
max(max(A))
ans=
2.1832
>>min(min(A))
ans=
-2.1707
(3).
sum(sum(A))
ans=
1.9666
sum(A,1)
ans=
0.01282.30950.25283.5884-4.1969
(4).
sort(A)
ans=
-1.6656-0.8323-1.5937-1.2025-2.1707
-1.1465-0.5883-1.4410-0.3999-1.6041
-0.4326-0.1867-1.3362-0.1567-1.0565
-0.0376-0.1364-0.6918-0.0198-0.9219
0.1253-0.09560.29440.6686-0.8051
0.17460.05930.57110.6900-0.0592
0.28770.11390.71430.71190.2193
0.32730.72580.85800.81560.2573
1.18921.06681.25401.19080.5287
1.19092.18321.62361.29021.4151
>>sort(ans,2,'descend')
ans=
-0.8323-1.2025-1.5937-1.6656-2.1707
-0.3999-0.5883-1.1465-1.4410-1.6041
-0.1567-0.1867-0.4326-1.0565-1.3362
-0.0198-0.0376-0.1364-0.6918-0.9219
0.66860.29440.1253-0.0956-0.8051
0.69000.57110.17460.0593-0.0592
0.71430.71190.28770.21930.1139
0.85800.81560.72580.32730.2573
1.25401.19081.18921.06680.5287
2.18321.62361.41511.29021.1909
2.
(2)n=1:
10;
a=n.*n;
interp1(n,a,2.2,'cubic')
ans=
4.8133
第七章
(1)g=inline('sin(x)./x');
>>[s,n]=quad(g,0,2)
s=
1.6054
n=
18
(2)
g=inline('1./((x-0.3).*(x-0.3)+0.01)-1./((x-0.9).*(x-0.9)+0.04)-6');
>>[s,n]=quad(g,0,1)
s=
11.7006
n=
145