matlab习题第三章Word下载.docx
《matlab习题第三章Word下载.docx》由会员分享,可在线阅读,更多相关《matlab习题第三章Word下载.docx(17页珍藏版)》请在冰豆网上搜索。
D'
otherwise
E'
end
else
错误:
输入的成绩不合理'
end
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);
ifa(i)<
c
c=a(i);
4、
a=[-3:
0.1:
3];
b=((exp(0.3.*a)-exp(-0.3.*a))./2)
c=sin(a+0.3)
y=b.*c+log((0.3+a)./2)
61
y=((exp(0.3.*a(i))-exp(-0.3.*a(i)))./2)*sin(a(i)+0.3)+log((0.3+a(i))/2)
end
b=
Columns1through10
-1.0265-0.9840-0.9423-0.9015-0.8615-0.8223-0.7838-0.7461-0.7090-0.6725
Columns11through20
-0.6367-0.6014-0.5666-0.5324-0.4986-0.4653-0.4325-0.4000-0.3678-0.3360
Columns21through30
-0.3045-0.2733-0.2423-0.2115-0.1810-0.1506-0.1203-0.0901-0.0600-0.0300
Columns31through40
00.03000.06000.09010.12030.15060.18100.21150.24230.2733
Columns41through50
0.30450.33600.36780.40000.43250.46530.49860.53240.56660.6014
Columns51through60
0.63670.67250.70900.74610.78380.82230.86150.90150.94230.9840
Column61
1.0265
c=
-0.4274-0.5155-0.5985-0.6755-0.7457-0.8085-0.8632-0.9093-0.9463-0.9738
-0.9917-0.9996-0.9975-0.9854-0.9636-0.9320-0.8912-0.8415-0.7833-0.7174
-0.6442-0.5646-0.4794-0.3894-0.2955-0.1987-0.09980.00000.09980.1987
0.29550.38940.47940.56460.64420.71740.78330.84150.89120.9320
0.96360.98540.99750.99960.99170.97380.94630.90930.86320.8085
0.74570.67550.59850.51550.42740.33500.23920.14110.0416-0.0584
-0.1577
y=
Columns1through5
0.7388+3.1416i0.7696+3.1416i0.7871+3.1416i0.7913+3.1416i0.7822+3.1416i
Columns6through10
0.7602+3.1416i0.7254+3.1416i0.6784+3.1416i0.6196+3.1416i0.5496+3.1416i
Columns11through15
0.4688+3.1416i0.3780+3.1416i0.2775+3.1416i0.1680+3.1416i0.0497+3.1416i
Columns16through20
-0.0771+3.1416i-0.2124+3.1416i-0.3566+3.1416i-0.5104+3.1416i-0.6752+3.1416i
Columns21through25
-0.8536+3.1416i-1.0497+3.1416i-1.2701+3.1416i-1.5271+3.1416i-1.8436+3.1416i
Columns26through30
-2.2727+3.1416i-2.9837+3.1416i-37.0245-3.0017-2.3085
Columns31through35
-1.8971-1.5978-1.3575-1.1531-0.9723
Columns36through40
-0.8083-0.6567-0.5151-0.3819-0.2561
Columns41through45
-0.1374-0.02550.07920.17660.2663
Columns46through50
0.34780.42060.48410.53790.5815
Columns51through55
0.61450.63660.64740.64700.6351
Columns56through60
0.61190.57770.53270.47740.4126
0.3388
0.7388+3.1416i
0.7696+3.1416i
0.7871+3.1416i
0.7913+3.1416i
0.7822+3.1416i
0.7602+3.1416i
0.7254+3.1416i
0.6784+3.1416i
0.6196+3.1416i
0.5496+3.1416i
0.4688+3.1416i
0.3780+3.1416i
0.2775+3.1416i
0.1680+3.1416i
0.0497+3.1416i
-0.0771+3.1416i
-0.2124+3.1416i
-0.3566+3.1416i
-0.5104+3.1416i
-0.6752+3.1416i
-0.8536+3.1416i
-1.0497+3.1416i
-1.2701+3.1416i
-1.5271+3.1416i
-1.8436+3.1416i
-2.2727+3.1416i
-2.9837+3.1416i
-37.0245
-3.0017
-2.3085
-1.8971
-1.5978
-1.3575
-1.1531
-0.9723
-0.8083
-0.6567
-0.5151
-0.3819
-0.2561
-0.1374
-0.0255
0.0792
0.1766
0.2663
0.3478
0.4206
0.4841
0.5379
0.5815
0.6145
0.6366
0.6474
0.6470
0.6351
0.6119
0.5777
0.5327
0.4774
0.4126
0.3388
5、
(1)n=input('
输入一个数:
a=0;
fori=i:
n
a=a+1/(i^2);
disp(a)
j=1:
n;
b=sum(1./(j.^2));
disp(b)
100
1.6350
1.6350
1000
1.6439
1.6439
10000
(2)
n=input('
a=1;
n
a=((2*i*i*2)/((2*i-1)*(2*i+1)))*a;
disp(a);
clear
i=1:
b=prod((2.*i).*(2.*i)./((2.*i-1).*(2.*i+1)))
1.5669
1.5704
1.5708
6、
a=rand(5,6);
n=input('
请输入一个数:
ifn>
5
n=5
a(n,:
)
输入超出范围'
)
5
ans=
0.89130.44470.17630.89360.13890.1988
6
n=
5
0.46600.67210.83180.18970.15090.5936
输入超出范围
7、
f1.m代码如下
functionm=f1(n)
m=n+10*log(n^2+5);
f2.m代码如下:
functionm=f2(n)
m=0;
m=m+i*(i+1);
在command界面中输入:
y1=f1(40)/(f1(30)+f1(20))
y1=
0.6390
>
y2=f2(40)/(f2(30)+f2(20))
y2=
1.7662
8、
函数文件factor1.m代码如下:
functionf=factor1(k)
ifk==1
f=1;
f=factor1(k-1)+k;
函数文件factor2.m代码如下:
functionf=factor2(k)
f=factor2(k-1)^2+k^2;
函数文件factor3.m代码如下:
functionf=factor3(k)
f=factor31/(k-1)+1/k;
思考练习
1、用MATLAB语言编写的程序称为M文件。
书P57下部。
N=[1,2,3,4,5]
N=
12345
A=N.*2
A=
246810
B=N./4
B=
0.25000.50000.75001.00001.2500
C=1./N
C=
1.00000.50000.33330.25000.2000
D=1./(N./2)./(N./2)/4
D=
1.00000.25000.11110.06250.0400
3、M文件
B=0;
A(i)=fix((99-10+1)*rand
(1)+10);
B=A(i)+B;
B=B/20;
ifA(i)<
B&
&
rem(A(i),2)==0
A(i)
输出结果:
66
18
24
22
4、
(1)M文件
A=1;
输入一个数'
fori=2:
A=(-1)^(i+1)*1/(2*n-1)+A;
A
输入一个数100
0.9950
factor3
输入一个数1000
0.9995
输入一个数10000
0.9999
(2)M文件
A=0;
n=input(‘输入一个数'
A=1/((4)^i)+A;
0.9999
0.3333
0.3333
M文件
function[m,n]=chengji(A,B)
m=A.*B;
n=A*B;
输出程序及结果:
a=[123;
456;
789];
b=[-101;
1-10;
011]
[m,n]=chengji(a,b);
disp('
a.*b='
a*b='
disp(n);
-101
1-10
011
a.*b=
-103
4-50
089
a*b=
114
1110
1116