MATLAB最全答案.docx
- 文档编号:4599577
- 上传时间:2022-12-07
- 格式:DOCX
- 页数:69
- 大小:38.62KB
MATLAB最全答案.docx
《MATLAB最全答案.docx》由会员分享,可在线阅读,更多相关《MATLAB最全答案.docx(69页珍藏版)》请在冰豆网上搜索。
MATLAB最全答案
数学实验(MATLAB)答案最全版
%Page20,ex1
(5)等于[exp
(1),exp
(2);exp(3),exp(4)]
(7)3=1*3,8=2*4
(8)a为各列最小值,b为最小值所在的行号
(10)1>=4,false,2>=3,false,3>=2,ture,4>=1,ture
(11)答案表明:
编址第2元素满足不等式(30>=20)和编址第4元素满足不等式(40>=10)
(12)答案表明:
编址第2行第1列元素满足不等式(30>=20)和编址第2行第2列元素满足不等式(40>=10)
%Page20,ex2
(1)a,b,c的值尽管都是1,但数据类型分别为数值,字符,逻辑,注意a与c相等,但他们不等于b
(2)double(fun)输出的分别是字符a,b,s,(,x,)的ASCII码
%Page20,ex3
>>r=2;p=0.5;n=12;
>>T=log(r)/n/log(1+0.01*p)
T=
11.5813
%Page20,ex4
>>x=-2:
0.05:
2;f=x.^4-2.^x;
>>[fmin,min_index]=min(f)
fmin=
-1.3907%最小值
min_index=
54%最小值点编址
>>x(min_index)
ans=
0.6500%最小值点
>>[f1,x1_index]=min(abs(f))%求近似根--绝对值最小的点
f1=
0.0328
x1_index=
24
>>x(x1_index)
ans=
-0.8500
>>x(x1_index)=[];f=x.^4-2.^x;%删去绝对值最小的点以求函数绝对值次小的点
>>[f2,x2_index]=min(abs(f))%求另一近似根--函数绝对值次小的点
f2=
0.0630
x2_index=
65
>>x(x2_index)
ans=
1.2500
%Page20,ex5
>>z=magic(10)
z=
929918156774515840
9880714167355576441
4818820225456637047
8587192136062697128
869325296168755234
17247683904249263365
2358289914830323966
7961395972931384572
10129496783537444653
111810077843643502759
>>sum(z)
ans=
505505505505505505505505505505
>>sum(diag(z))
ans=
505
>>z(:
2)/sqrt(3)
ans=
57.1577
46.1880
46.7654
50.2295
53.6936
13.8564
2.8868
3.4641
6.9282
10.3923
>>z(8,:
)=z(8,:
)+z(3,:
)
z=
929918156774515840
9880714167355576441
4818820225456637047
8587192136062697128
869325296168755234
17247683904249263365
2358289914830323966
83871011151198387101115119
10129496783537444653
111810077843643502759
%Page40ex1
先在编辑器窗口写下列M函数,保存为eg2_1.m
function[xbar,s]=ex2_1(x)
n=length(x);
xbar=sum(x)/n;
s=sqrt((sum(x.^2)-n*xbar^2)/(n-1));
例如
>>x=[81706551766690876177];
>>[xbar,s]=ex2_1(x)
xbar=
72.4000
s=
12.1124
%Page40ex2
s=log
(1);n=0;
whiles<=100
n=n+1;
s=s+log(1+n);
end
m=n
计算结果m=37
%Page40ex3
clear;
F
(1)=1;F
(2)=1;k=2;x=0;
e=1e-8;a=(1+sqrt(5))/2;
whileabs(x-a)>e
k=k+1;F(k)=F(k-1)+F(k-2);x=F(k)/F(k-1);
end
a,x,k
计算至k=21可满足精度
%Page40ex4
clear;tic;s=0;
fori=1:
1000000
s=s+sqrt(3)/2^i;
end
s,toc
tic;s=0;i=1;
whilei<=1000000
s=s+sqrt(3)/2^i;i=i+1;
end
s,toc
tic;s=0;
i=1:
1000000;
s=sqrt(3)*sum(1./2.^i);
s,toc
%Page40ex5
t=0:
24;
c=[15141414141516182022232528...
313231292725242220181716];
plot(t,c)
%Page40ex6
%
(1)
x=-2:
0.1:
2;y=x.^2.*sin(x.^2-x-2);plot(x,y)
y=inline('x^2*sin(x^2-x-2)');fplot(y,[-22])
%
(2)参数方法
t=linspace(0,2*pi,100);
x=2*cos(t);y=3*sin(t);plot(x,y)
%(3)
x=-3:
0.1:
3;y=x;
[x,y]=meshgrid(x,y);
z=x.^2+y.^2;
surf(x,y,z)
%(4)
x=-3:
0.1:
3;y=-3:
0.1:
13;
[x,y]=meshgrid(x,y);
z=x.^4+3*x.^2+y.^2-2*x-2*y-2*x.^2.*y+6;
surf(x,y,z)
%(5)
t=0:
0.01:
2*pi;
x=sin(t);y=cos(t);z=cos(2*t);
plot3(x,y,z)
%(6)
theta=linspace(0,2*pi,50);fai=linspace(0,pi/2,20);
[theta,fai]=meshgrid(theta,fai);
x=2*sin(fai).*cos(theta);
y=2*sin(fai).*sin(theta);z=2*cos(fai);
surf(x,y,z)
%(7)
x=linspace(0,pi,100);
y1=sin(x);y2=sin(x).*sin(10*x);y3=-sin(x);
plot(x,y1,x,y2,x,y3)
%page41,ex7
x=-1.5:
0.05:
1.5;
y=1.1*(x>1.1)+x.*(x<=1.1).*(x>=-1.1)-1.1*(x<-1.1);
plot(x,y)
%page41,ex8
分别使用whichtrapz,typetrapz,dirC:
\MATLAB7\toolbox\matlab\datafun\
%page41,ex9
clear;close;
x=-2:
0.1:
2;y=x;
[x,y]=meshgrid(x,y);
a=0.5457;b=0.7575;
p=a*exp(-0.75*y.^2-3.75*x.^2-1.5*x).*(x+y>1);
p=p+b*exp(-y.^2-6*x.^2).*(x+y>-1).*(x+y<=1);
p=p+a*exp(-0.75*y.^2-3.75*x.^2+1.5*x).*(x+y<=-1);
mesh(x,y,p)
%page41,ex10
lookforlyapunov
helplyap
>>A=[123;456;780];C=[2-5-22;-5-24-56;-22-56-16];
>>X=lyap(A,C)
X=
1.0000-1.0000-0.0000
-1.00002.00001.0000
-0.00001.00007.0000
%Chapter3
%Exercise1
>>a=[1,2,3];b=[2,4,3];a./b,a.\b,a/b,a\b
ans=
0.50000.50001.0000
ans=
221
ans=
0.6552%一元方程组x[2,4,3]=[1,2,3]的近似解
ans=
000
000
0.66671.33331.0000
%矩阵方程[1,2,3][x11,x12,x13;x21,x22,x23;x31,x32,x33]=[2,4,3]的特解
%Exercise2
(1)
>>A=[41-1;32-6;1-53];b=[9;-2;1];
>>rank(A),rank([A,b])%[A,b]为增广矩阵
ans=
3
ans=
3%可见方程组唯一解
>>x=A\b
x=
2.3830
1.4894
2.0213
%Exercise2
(2)
>>A=[4-33;32-6;1-53];b=[-1;-2;1];
>>rank(A),rank([A,b])
ans=
3
ans=
3%可见方程组唯一解
>>x=A\b
x=
-0.4706
-0.2941
0
%Exercise2(3)
>>A=[41;32;1-5];b=[1;1;1];
>>rank(A),rank([A,b])
ans=
2
ans=
3%可见方程组无解
>>x=A\b
x=
0.3311
-0.1219%最小二乘近似解
%Exercise2(4)
>>a=[2,1,-1,1;1,2,1,-1;1,1,2,1];b=[123]';%注意b的写法
>>rank(a),rank([a,b])
ans=
3
ans=
3%rank(a)==rank([a,b])<4说明有无穷多解
>>a\b
ans=
1
0
1
0%一个特解
%Exercise3
>>a=[2,1,-1,1;1,2,1,-1;1,1,2,1];b=[1,2,3]';
>>x=null(a),x0=a\b
x=
-0.6255
0.6255
-0.2085
0.4170
x0=
1
0
1
0
%通解kx+x0
%Exercise4
>>x0=[0.20.8]';a=[0.990.05;0.010.95];
>>x1=a*x,x2=a^2*x,x10=a^10*x
>>x=x0;fori=1:
1000,x=a*x;end,x
x=
0.8333
0.1667
>>x0=[0.80.2]';
>>x=x0;fori=1:
1000,x=a*x;end,x
x=
0.8333
0.1667
>>[v,e]=eig(a)
v=
0.9806-0.7071
0.19610.7071
e=
1.00000
00.9400
>>v(:
1)./x
ans=
1.1767
1.1767%成比例,说明x是最大特征值对应的特征向量
%Exercise5
%用到公式(3.11)(3.12)
>>B=[6,2,1;2.25,1,0.2;3,0.2,1.8];x=[25520]';
>>C=B/diag(x)
C=
0.24000.40000.0500
0.09000.20000.0100
0.12000.04000.0900
>>A=eye(3,3)-C
A=
0.7600-0.4000-0.0500
-0.09000.8000-0.0100
-0.1200-0.04000.9100
>>D=[171717]';x=A\D
x=
37.5696
25.7862
24.7690
%Exercise6
(1)
>>a=[41-1;32-6;1-53];det(a),inv(a),[v,d]=eig(a)
ans=
-94
ans=
0.2553-0.02130.0426
0.1596-0.1383-0.2234
0.1809-0.2234-0.0532
v=
0.0185-0.9009-0.3066
-0.7693-0.1240-0.7248
-0.6386-0.41580.6170
d=
-3.052700
03.67600
008.3766
%Exercise6
(2)
>>a=[11-1;02-1;-120];det(a),inv(a),[v,d]=eig(a)
ans=
1
ans=
2.0000-2.00001.0000
1.0000-1.00001.0000
2.0000-3.00002.0000
v=
-0.57730.5774+0.0000i0.5774-0.0000i
-0.57730.57740.5774
-0.57740.5773-0.0000i0.5773+0.0000i
d=
1.000000
01.0000+0.0000i0
001.0000-0.0000i
%Exercise6(3)
>>A=[5765;71087;68109;57910]
A=
5765
71087
68109
57910
>>det(A),inv(A),[v,d]=eig(A)
ans=
1
ans=
68.0000-41.0000-17.000010.0000
-41.000025.000010.0000-6.0000
-17.000010.00005.0000-3.0000
10.0000-6.0000-3.00002.0000
v=
0.83040.09330.39630.3803
-0.5016-0.30170.61490.5286
-0.20860.7603-0.27160.5520
0.1237-0.5676-0.62540.5209
d=
0.0102000
00.843100
003.85810
00030.2887
%Exercise6(4)(以n=5为例)
%关键是矩阵的定义
%方法一(三个for)
n=5;
fori=1:
n,a(i,i)=5;end
fori=1:
(n-1),a(i,i+1)=6;end
fori=1:
(n-1),a(i+1,i)=1;end
a
%方法二(一个for)
n=5;a=zeros(n,n);
a(1,1:
2)=[56];
fori=2:
(n-1),a(i,[i-1,i,i+1])=[156];end
a(n,[n-1n])=[15];
a
%方法三(不用for)
n=5;a=diag(5*ones(n,1));
b=diag(6*ones(n-1,1));
c=diag(ones(n-1,1));
a=a+[zeros(n-1,1),b;zeros(1,n)]+[zeros(1,n);c,zeros(n-1,1)]
%下列计算
>>det(a)
ans=
665
>>inv(a)
ans=
0.3173-0.58651.0286-1.62411.9489
-0.09770.4887-0.85711.3534-1.6241
0.0286-0.14290.5429-0.85711.0286
-0.00750.0376-0.14290.4887-0.5865
0.0015-0.00750.0286-0.09770.3173
>>[v,d]=eig(a)
v=
-0.7843-0.7843-0.92370.9860-0.9237
0.5546-0.5546-0.3771-0.00000.3771
-0.2614-0.26140.0000-0.16430.0000
0.0924-0.09240.0628-0.0000-0.0628
-0.0218-0.02180.02570.02740.0257
d=
0.75740000
09.2426000
007.449500
0005.00000
00002.5505
%Exercise7
(1)
>>a=[41-1;32-6;1-53];[v,d]=eig(a)
v=
0.0185-0.9009-0.3066
-0.7693-0.1240-0.7248
-0.6386-0.41580.6170
d=
-3.052700
03.67600
008.3766
>>det(v)
ans=
-0.9255%v行列式正常,特征向量线性相关,可对角化
>>inv(v)*a*v%验算
ans=
-3.05270.0000-0.0000
0.00003.6760-0.0000
-0.0000-0.00008.3766
>>[v2,d2]=jordan(a)%也可用jordan
v2=
0.07980.00760.9127
0.1886-0.31410.1256
-0.1605-0.26070.4213%特征向量不同
d2=
8.376600
0-3.0527-0.0000i0
003.6760+0.0000i
>>v2\a*v2
ans=
8.376600.0000
0.0000-3.05270.0000
0.00000.00003.6760
>>v(:
1)./v2(:
2)%对应相同特征值的特征向量成比例
ans=
2.4491
2.4491
2.4491
%Exercise7
(2)
>>a=[11-1;02-1;-120];[v,d]=eig(a)
v=
-0.57730.5774+0.0000i0.5774-0.0000i
-0.57730.57740.5774
-0.57740.5773-0.0000i0.5773+0.0000i
d=
1.000000
01.0000+0.0000i0
001.0000-0.0000i
>>det(v)
ans=
-5.0566e-028-5.1918e-017i%v的行列式接近0,特征向量线性相关,不可对角化
>>[v,d]=jordan(a)
v=
101
100
1-10
d=
110
011
001%jordan标准形不是对角的,所以不可对角化
%Exercise7(3)
>>A=[5765;71087;68109;57910]
A=
5765
71087
68109
57910
>>[v,d]=eig(A)
v=
0.83040.09330.39630.3803
-0.5016-0.30170.61490.5286
-0.20860.7603-0.27160.5520
0.1237-0.5676-0.62540.5209
d=
0.0102000
00.843100
003.85810
00030.2887
>>inv(v)*A*v
ans=
0.01020.0000-0.00000.0000
0.00000.8431-0.0000-0.0000
-0.00000.00003.8581-0.0000
-0.0000-0.0000030.2887
%本题用jordan不行,原因未知
%Exercise7(4)参考6(4)和7
(1),略
%Exercise8只有(3)对称,且特征值全部大于零,所以是正定矩阵.
%Exercise9
(1)
>>a=[4-313;2-135;1-1-1-1;3-234;7-6-70]
>>rank(a)
ans=
3
>>rank(a(1:
3,:
))
ans=
2
>>rank(a([124],:
))%1,2,4行为最大无关组
ans=
3
>>b=a([124],:
)';c=a([35],:
)';
>>b\c%线性表示的系数
ans=
0.50005.0000
-0.50001.0000
0-5.0000
%Exercise10
>>a=[1-22;-2-24;24-2]
>>[v,d]=eig(a)
v=
0.33330.9339-0.1293
0.6667-0.3304-0.6681
-0.66670.1365-0.7327
d=
-7.000000
02.00000
002.0000
>>v'*v
ans=
1.00000.00000.0000
0.00001.00000
0.000001.000
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- MATLAB 答案
![提示](https://static.bdocx.com/images/bang_tan.gif)