东华大学MATLAB数学实验第二版解答Word文档格式.docx
《东华大学MATLAB数学实验第二版解答Word文档格式.docx》由会员分享,可在线阅读,更多相关《东华大学MATLAB数学实验第二版解答Word文档格式.docx(34页珍藏版)》请在冰豆网上搜索。
x=-2:
0.05:
2;
f=x.^4-2.^x;
[fmin,min_index]=min(f)
最小值最小值点编址
x(min_index)
ans=
0.6500最小值点
[f1,x1_index]=min(abs(f))求近似根--绝对值最小的点
f1=
0.0328
x1_index=
24
x(x1_index)
-0.8500
x(x1_index)=[];
删去绝对值最小的点以求函数绝对值次小的点
[f2,x2_index]=min(abs(f))求另一近似根--函数绝对值次小的点
f2=
0.0630
x2_index=
65
x(x2_index)
1.2500
Page20,ex5
z=magic(10)
z=
929918156774515840
9880714167355576441
4818820225456637047
8587192136062697128
869325296168755234
17247683904249263365
2358289914830323966
7961395972931384572
10129496783537444653
111810077843643502759
sum(z)
sum(diag(z))
z(:
2)/sqrt(3)
z(8,:
)=z(8,:
)+z(3,:
)
Chapter2
Page45ex1
先在编辑器窗口写下列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)
Page45ex2
s=log
(1);
n=0;
whiles<
=100
n=n+1;
s=s+log(1+n);
end
m=n
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);
a,x,k
计算至k=21可满足精度
Page45ex4
tic;
s=0;
fori=1:
1000000
s=s+sqrt(3)/2^i;
s,toc
i=1;
whilei<
=1000000
i=i+1;
i=1:
1000000;
s=sqrt(3)*sum(1./2.^i);
Page45ex5
t=0:
24;
c=[15141414141516182022232528...
313231292725242220181716];
plot(t,c)
Page45ex6
(1)
x=-2:
0.1:
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:
3;
y=x;
[x,y]=meshgrid(x,y);
z=x.^2+y.^2;
surf(x,y,z)
(4)
y=-3:
13;
z=x.^4+3*x.^2+y.^2-2*x-2*y-2*x.^2.*y+6;
(5)
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);
(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)
page45,ex7
x=-1.5:
1.5;
y=1.1*(x>
1.1)+x.*(x<
=1.1).*(x>
=-1.1)-1.1*(x<
-1.1);
page45,ex9
close;
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)
page45,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
Page65Ex1
a=[1,2,3];
b=[2,4,3];
a./b,a.\b,a/b,a\b
0.50000.50001.0000
221
0.6552一元方程组x[2,4,3]=[1,2,3]的近似解
000
0.66671.33331.0000
矩阵方程[1,2,3][x11,x12,x13;
x21,x22,x23;
x31,x32,x33]=[2,4,3]的特解
Page65Ex2
A=[41-1;
32-6;
1-53];
b=[9;
-2;
1];
rank(A),rank([A,b])[A,b]为增广矩阵
3
3可见方程组唯一解
x=A\b
x=
2.3830
1.4894
2.0213
(2)
A=[4-33;
b=[-1;
rank(A),rank([A,b])
-0.4706
-0.2941
0
(3)
A=[41;
32;
1-5];
b=[1;
1;
2
3可见方程组无解
0.3311
-0.1219最小二乘近似解
(4)
a=[2,1,-1,1;
1,2,1,-1;
1,1,2,1];
b=[123]'
;
%注意b的写法
rank(a),rank([a,b])
3rank(a)==rank([a,b])<
4说明有无穷多解
a\b
1
0一个特解
Page65Ex3
b=[1,2,3]'
x=null(a),x0=a\b
-0.6255
0.6255
-0.2085
0.4170
x0=
通解kx+x0
Page65Ex4
x0=[0.20.8]'
a=[0.990.05;
0.010.95];
x1=a*x,x2=a^2*x,x10=a^10*x
x=x0;
1000,x=a*x;
end,x
0.8333
0.1667
x0=[0.80.2]'
[v,e]=eig(a)
v=
0.9806-0.7071
0.19610.7071
e=
1.00000
00.9400
v(:
1)./x
1.1767
1.1767成比例,说明x是最大特征值对应的特征向量
Page65Ex5
用到公式(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.04