matlab数学实验答案(胡良剑)
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
%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 =
lookfor lyapunov
help lyap
>> A=[1 2 3;4 5 6;7 8 0];C=[2 -5 -22;-5 -24 -56;-22 -56 -16];
>> X=lyap(A,C)
X =
1.0000 -1.0000 -0.0000
-1.0000 2.0000 1.0000
-0.0000 1.0000 7.0000
>> x=null(a),x0=a\b
x =
-0.6255
0.6255
-0.2085
0.4170
x0 =
1
0
1
0
%通解kx+x0
%Exercise 4
>> x0=[0.2 0.8]';a=[0.99 0.05;0.01 0.95];
>> x1=a*x, x2=a^2*x, x10=a^10*x
>> x=x0;for i=1:1000,x=a*x;end,x
%矩阵方程[1,2,3][x11,x12,x13;x21,x22,x23;x31,x32,x33]=[2,4,3]的特解
%Exercise 2(1)
>> A=[4 1 -1;3 2 -6;1 -5 3];b=[9;-2;1];
>> rank(A), rank([A,b]) %[A,b]为增广矩阵
ans =
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
4 81 88 20 22 54 56 63 70 47
85 87 19 21 3 60 62 69 71 28
86 93 25 2 9 61 68 75 52 34
17 24 76 83 90 42 49 26 33 65
23 5 82 89 91 48 30 32 39 66
79 6 13 95 97 29 31 38 45 72
4 81 88 20 22 54 56 63 70 47
85 87 19 21 3 60 62 69 71 28
86 93 25 2 9 61 68 75 52 34
17 24 76 83 90 42 49 26 33 65
23 5 82 89 91 48 30 32 39 66
83 87 101 115 119 83 87 101 115 119
例如
>>x=[81 70 65 51 76 66 90 87 61 77];
>>[xbar,s]=ex2_1(x)
xbar =
72.4000
s =
12.1124
%Page 40 ex2
s=lห้องสมุดไป่ตู้g(1);n=0;
while s<=100
n=n+1;
s=s+log(1+n);
end
m=n
计算结果m=37
3
ans =
3 %可见方程组唯一解
>> x=A\b
x =
2.3830
1.4894
2.0213
%Exercise 2(2)
>> A=[4 -3 3;3 2 -6;1 -5 3];b=[-1;-2;1];
>> rank(A), rank([A,b])
ans =
3
ans =
3 %可见方程组唯一解
>> x=A\b
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);
plot(x,y)
%page41,ex8
分别使用which trapz, type trapz, dir C:\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;
>> [f2,x2_index]=min(abs(f)) %求另一近似根--函数绝对值次小的点
f2 =
0.0630
x2_index =
65
>> x(x2_index)
ans =
1.2500
%Page20,ex5
>> z=magic(10)
z =
92 99 1 8 15 67 74 51 58 40
98 80 7 14 16 73 55 57 64 41
clear;tic;s=0;
for i=1:1000000
s=s+sqrt(3)/2^i;
end
s,toc
tic;s=0;i=1;
while i<=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);
10 12 94 96 78 35 37 44 46 53
11 18 100 77 84 36 43 50 27 59
>> sum(z)
ans =
505 505 505 505 505 505 505 505 505 505
>> sum(diag(z))
ans =
505
>> z(:,2)/sqrt(3)
10 12 94 96 78 35 37 44 46 53
11 18 100 77 84 36 43 50 27 59
%Page 40 ex1
先在编辑器窗口写下列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));
s,toc
%Page 40 ex5
t=0:24;
c=[15 14 14 14 14 15 16 18 20 22 23 25 28 ...
31 32 31 29 27 25 24 22 20 18 17 16];
plot(t,c)
%Page 40 ex6
%(1)
x=-2:0.1:2;y=x.^2.*sin(x.^2-x-2);plot(x,y)
0.0900 0.2000 0.0100
0.1200 0.0400 0.0900
>> A=eye(3,3)-C
A =
0.7600 -0.4000 -0.0500
-0.0900 0.8000 -0.0100
-0.1200 -0.0400 0.9100
>> D=[17 17 17]';x=A\D
x =
37.5696
%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)
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);
y=inline('x^2*sin(x^2-x-2)');fplot(y,[-2 2])
%(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;
%Chapter 3
%Exercise 1
>> a=[1,2,3];b=[2,4,3];a./b,a.\b,a/b,a\b
ans =
0.5000 0.5000 1.0000
ans =
2 2 1
ans =
0.6552 %一元方程组x[2,4,3]=[1,2,3]的近似解
ans =
0 0 0
0 0 0
0.6667 1.3333 1.0000
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; %删去绝对值最小的点以求函数绝对值次小的点
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 =
92 99 1 8 15 67 74 51 58 40
98 80 7 14 16 73 55 57 64 41
%Page 40 ex3
clear;
F(1)=1;F(2)=1;k=2;x=0;
e=1e-8; a=(1+sqrt(5))/2;
while abs(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可满足精度
%Page 40 ex4
>> a=[2,1,-1,1;1,2,1,-1;1,1,2,1];b=[1 2 3]';%注意b的写法
>> rank(a),rank([a,b])
ans =
3
ans =
3 %rank(a)==rank([a,b])<4说明有无穷多解
>> a\b
ans =
1
0
1
0 %一个特解
%Exercise 3
>> a=[2,1,-1,1;1,2,1,-1;1,1,2,1];b=[1,2,3]';
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);
25.7862
24.7690
%Exercise 6(1)
>> a=[4 1 -1;3 2 -6;1 -5 3];det(a),inv(a),[v,d]=eig(a)
(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码
ans =
1.1767
1.1767 %成比例,说明x是最大特征值对应的特征向量
%Exercise 5
%用到公式(3.11)(3.12)
>> B=[6,2,1;2.25,1,0.2;3,0.2,1.8];x=[25 5 20]';
>> C=B/diag(x)
C =
0.2400 0.4000 0.0500
x =
-0.4706
-0.2941
0
%Exercise 2(3)
>> A=[4 1;3 2;1 -5];b=[1;1;1];
>> rank(A), rank([A,b])
ans =
2
ans =
3 %可见方程组无解
>> x=A\b
x =
0.3311
-0.1219 %最小二乘近似解
%Exercise 2(4)
x =
0.8333
0.1667
>> x0=[0.8 0.2]';
>> x=x0;for i=1:1000,x=a*x;end,x
x =
0.8333
0.1667
>> [v,e]=eig(a)
v =
0.9806 -0.7071
0.1961 0.7071
e =
1.0000 0
0 0.9400
>> v(:,1)./x
>> 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 =
lookfor lyapunov
help lyap
>> A=[1 2 3;4 5 6;7 8 0];C=[2 -5 -22;-5 -24 -56;-22 -56 -16];
>> X=lyap(A,C)
X =
1.0000 -1.0000 -0.0000
-1.0000 2.0000 1.0000
-0.0000 1.0000 7.0000
>> x=null(a),x0=a\b
x =
-0.6255
0.6255
-0.2085
0.4170
x0 =
1
0
1
0
%通解kx+x0
%Exercise 4
>> x0=[0.2 0.8]';a=[0.99 0.05;0.01 0.95];
>> x1=a*x, x2=a^2*x, x10=a^10*x
>> x=x0;for i=1:1000,x=a*x;end,x
%矩阵方程[1,2,3][x11,x12,x13;x21,x22,x23;x31,x32,x33]=[2,4,3]的特解
%Exercise 2(1)
>> A=[4 1 -1;3 2 -6;1 -5 3];b=[9;-2;1];
>> rank(A), rank([A,b]) %[A,b]为增广矩阵
ans =
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
4 81 88 20 22 54 56 63 70 47
85 87 19 21 3 60 62 69 71 28
86 93 25 2 9 61 68 75 52 34
17 24 76 83 90 42 49 26 33 65
23 5 82 89 91 48 30 32 39 66
79 6 13 95 97 29 31 38 45 72
4 81 88 20 22 54 56 63 70 47
85 87 19 21 3 60 62 69 71 28
86 93 25 2 9 61 68 75 52 34
17 24 76 83 90 42 49 26 33 65
23 5 82 89 91 48 30 32 39 66
83 87 101 115 119 83 87 101 115 119
例如
>>x=[81 70 65 51 76 66 90 87 61 77];
>>[xbar,s]=ex2_1(x)
xbar =
72.4000
s =
12.1124
%Page 40 ex2
s=lห้องสมุดไป่ตู้g(1);n=0;
while s<=100
n=n+1;
s=s+log(1+n);
end
m=n
计算结果m=37
3
ans =
3 %可见方程组唯一解
>> x=A\b
x =
2.3830
1.4894
2.0213
%Exercise 2(2)
>> A=[4 -3 3;3 2 -6;1 -5 3];b=[-1;-2;1];
>> rank(A), rank([A,b])
ans =
3
ans =
3 %可见方程组唯一解
>> x=A\b
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);
plot(x,y)
%page41,ex8
分别使用which trapz, type trapz, dir C:\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;
>> [f2,x2_index]=min(abs(f)) %求另一近似根--函数绝对值次小的点
f2 =
0.0630
x2_index =
65
>> x(x2_index)
ans =
1.2500
%Page20,ex5
>> z=magic(10)
z =
92 99 1 8 15 67 74 51 58 40
98 80 7 14 16 73 55 57 64 41
clear;tic;s=0;
for i=1:1000000
s=s+sqrt(3)/2^i;
end
s,toc
tic;s=0;i=1;
while i<=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);
10 12 94 96 78 35 37 44 46 53
11 18 100 77 84 36 43 50 27 59
>> sum(z)
ans =
505 505 505 505 505 505 505 505 505 505
>> sum(diag(z))
ans =
505
>> z(:,2)/sqrt(3)
10 12 94 96 78 35 37 44 46 53
11 18 100 77 84 36 43 50 27 59
%Page 40 ex1
先在编辑器窗口写下列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));
s,toc
%Page 40 ex5
t=0:24;
c=[15 14 14 14 14 15 16 18 20 22 23 25 28 ...
31 32 31 29 27 25 24 22 20 18 17 16];
plot(t,c)
%Page 40 ex6
%(1)
x=-2:0.1:2;y=x.^2.*sin(x.^2-x-2);plot(x,y)
0.0900 0.2000 0.0100
0.1200 0.0400 0.0900
>> A=eye(3,3)-C
A =
0.7600 -0.4000 -0.0500
-0.0900 0.8000 -0.0100
-0.1200 -0.0400 0.9100
>> D=[17 17 17]';x=A\D
x =
37.5696
%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)
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);
y=inline('x^2*sin(x^2-x-2)');fplot(y,[-2 2])
%(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;
%Chapter 3
%Exercise 1
>> a=[1,2,3];b=[2,4,3];a./b,a.\b,a/b,a\b
ans =
0.5000 0.5000 1.0000
ans =
2 2 1
ans =
0.6552 %一元方程组x[2,4,3]=[1,2,3]的近似解
ans =
0 0 0
0 0 0
0.6667 1.3333 1.0000
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; %删去绝对值最小的点以求函数绝对值次小的点
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 =
92 99 1 8 15 67 74 51 58 40
98 80 7 14 16 73 55 57 64 41
%Page 40 ex3
clear;
F(1)=1;F(2)=1;k=2;x=0;
e=1e-8; a=(1+sqrt(5))/2;
while abs(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可满足精度
%Page 40 ex4
>> a=[2,1,-1,1;1,2,1,-1;1,1,2,1];b=[1 2 3]';%注意b的写法
>> rank(a),rank([a,b])
ans =
3
ans =
3 %rank(a)==rank([a,b])<4说明有无穷多解
>> a\b
ans =
1
0
1
0 %一个特解
%Exercise 3
>> a=[2,1,-1,1;1,2,1,-1;1,1,2,1];b=[1,2,3]';
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);
25.7862
24.7690
%Exercise 6(1)
>> a=[4 1 -1;3 2 -6;1 -5 3];det(a),inv(a),[v,d]=eig(a)
(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码
ans =
1.1767
1.1767 %成比例,说明x是最大特征值对应的特征向量
%Exercise 5
%用到公式(3.11)(3.12)
>> B=[6,2,1;2.25,1,0.2;3,0.2,1.8];x=[25 5 20]';
>> C=B/diag(x)
C =
0.2400 0.4000 0.0500
x =
-0.4706
-0.2941
0
%Exercise 2(3)
>> A=[4 1;3 2;1 -5];b=[1;1;1];
>> rank(A), rank([A,b])
ans =
2
ans =
3 %可见方程组无解
>> x=A\b
x =
0.3311
-0.1219 %最小二乘近似解
%Exercise 2(4)
x =
0.8333
0.1667
>> x0=[0.8 0.2]';
>> x=x0;for i=1:1000,x=a*x;end,x
x =
0.8333
0.1667
>> [v,e]=eig(a)
v =
0.9806 -0.7071
0.1961 0.7071
e =
1.0000 0
0 0.9400
>> v(:,1)./x