中南大学matlab课后习题7Word文件下载.docx
《中南大学matlab课后习题7Word文件下载.docx》由会员分享,可在线阅读,更多相关《中南大学matlab课后习题7Word文件下载.docx(52页珍藏版)》请在冰豆网上搜索。
,1:
2)D=A(2:
4,3:
4)E=B*C
(3)E<
DE&
DE|D~E|~D
5.A=[-29,6,18;
20,5,12;
-8,8,5];
[V,D]=eig(A)
A*V=V*D
第三章
1.f=input('
输入一个数:
'
'
s'
f(end:
-1:
1)
2.
(1)if语句
score=input('
请输入成绩:
ifscore>
=90&
&
score<
=100
disp('
A'
elseifscore>
=80&
=89
B'
=70&
=79
C'
=60&
=69;
D'
elseifscore<
60&
score>
=0;
E'
else
出错'
End
(2)用switch语句
switchfix(score/10)
case{9,10}
case{8}
case{7}
case{6}
case{0,1,2,3,4,5}
otherwise
3.b=max(a)
c=min(a)
b=0
c=0
fori=1:
20
ifa(i)>
b
b=a(i);
end
ifa(i)<
c
c=a(i);
End
4.a=[-3:
0.1:
3];
b=((exp(0.3.*a)-exp(-0.3.*a))./2)
c=sin(a+0.3)
61
y=(exp(0.3*a(i))-exp(-0.3*a(i)))/2*sin(a(i)+0.3)+log((0.3+a(i))/2)
5.
(1)A=0;
n=100
n
A=1/n/n+A;
(2)A=1;
n=10000;
A=(2*n*n*2)/((2*n-1)*(2*n+1))*A;
6.A=rand(5,6)
n=input('
Ç
ë
Ê
ä
È
Ò
»
¸
ö
n'
ifn>
5
n=5
A(n,n)
else
A(n)
7.f1.m代码:
functionm=f1(n)
m=n+10*log(n^2+5);
f2.m代码:
functionm=f2(n)
m=0;
fori=1:
m=m+i*(i+1);
end
在命令文件p3_11.m中调用f1.m和f2.m
p3_11.m代码如下:
y1=f1(40)/(f1(30)+f1(20));
y2=f2(40)/(f2(30)+f2(20));
y1
y2
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;
函数文件factor3.m代码:
functionf=factor3(k)
f=factor3(k-1)+1/k;
2.N=[1,2,3,4,5]
A=N.*2
B=N./4
C=1./N
D=1./(N./2)./(N./2)/4
3.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)
第4章.
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)t=0:
0.01:
2*pi;
x=8.*cos(t);
y=4*sqrt
(2).*sin(t);
plot(x,y)
2.t=-pi:
pi/10:
pi;
y=1./(1+exp(-t));
subplot(2,2,1);
bar(t,y,'
b'
)'
axis([-5,5,-3,3]);
subplot(2,2,2);
stairs(t,y,'
k'
stairs(t,y,'
subplot(2,2,3);
stem(t,y,'
m'
stem(t,y,'
subplot(2,2,4);
loglog(t,y,'
g'
3.
(1)t=0:
pi/100:
y=5*cos(t)+4;
polar(t,y,'
-*'
)
(2)t=-pi/3:
pi/3;
r=5*sin(t).^2./cos(t);
polar(t,r,'
4.
(1)t=0:
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;
5.[x,y,z]=sphere(50);
m=moviein(100);
100
surf(i*x,i*y,i*z);
shadinginterp
colormap(hot);
axisequal
axis([-100,100,-100,100,-100,100])
axisoff
m(:
i)=getframe;
2.
(1)x=1:
10
a=exp((x.^2)/2)
y=a.*1/2/pi
plot(x,y)
(2)t=-pi:
2*pi
X=t.*sin(t)
Y=t.*cos(t)
plot(X,Y)
3.t=0:
0.00005:
x=sin(3*t).*cos(t);
y1=2*x-0.5;
y2=sin(3*t).*sin(t);
plot(x,y2,x,y1);
holdon
k=find(abs(y2-y1)<
1e-4);
x1=x(k);
y3=2*x1-0.5;
plot(x1,y3,'
rp'
4.x=-pi*6:
pi*6
y=sin(1./x)
fplot('
sin(1./x)'
[-pi*6,pi*6],1e-4)
5.
(1)x=1:
y=12./x
polar(x,y)
(2)x=-pi/6:
pi/6
y=3*sin(x).*cos(x)./(sin(x).^3+cos(x).^3)
6.
(1)[u,v]=meshgrid(-pi:
pi);
x=3*u.*sin(v);
y=2*u.*cos(v);
z=4*u.*u;
mesh(x,y,z);
(2)[x,y]=meshgrid(-3:
6/100:
3);
z=-5./(1+x.*x+y.*y);
mesh(x,y,z)
第五章
1.A=randn(10,5)
(1)X=mean(A)
Y=std(A,0,1)
(2)max(max(A))
min(min(A))
(3)B=sum(A,2)
sum(B)
(4)sort(A);
sort(A,2,'
descend'
(1)t=0:
15:
90;
x1=[0,0.2588,0.5000,0.7071,0.8660,0.9659,1.0000];
a1=0:
1:
y1=interp1(t,x1,a1,'
spline'
x2=[0,0.2679,0.5774,1.0000,1.7320,3.7320,NaN];
a2=0:
75;
y2=interp1(t,x2,a2,'
p1=polyfit(t,x1,5);
Z1=polyval(p1,a1)
p2=polyfit(t,x2,5);
z2=polyval(p2,a2)
(2)X=[149162536496481100];
Y=1:
10;
X1=1:
100;
Y1=interp1(X,Y,X1,'
cubic'
3.
4.P=[2,-3,5,13];
Q=[1,5,8];
p=polyder(P)
p1=polyder(P,Q)
[p,q]=polyder(P,Q)
5.P1=[1,2,4,0,5];
P2=[1,0];
P3=[1,2,3];
1)P4=conv(P2,P3)
P4=[0,1,2,3,0];
P=P1+P4
2)x=roots(P)
3)A=[-1,1.2,-1.4;
0.75,2,3.5;
0,5,2.5];
Y=polyval(P,A)
4)Z=polyvalm(P,A)
第六章
(1)>
>
A=[1/2,1/3,1/4;
1/3,1/4,1/5;
1/4,1/5,1/6];
B=[0.95,0.67,0.52]'
;
x=A\B
(2)>
B=[0.95,0.67,0.53]'
(3)>
cond(A)
(1)建立函数文件funx.m,命令如下;
Functionfx=funx(x)
fx=x^41+x^3+1;
调用fzero函数求根,命令如下;
z=fzero(@funx,-1)
(2)建立函数文件sin.m,命令如下;
Functionfx=sin(x)
fx=x-(sin(x))/x;
z=fzero(@sin,0.5)
(3)建立函数文件myfun.m,命令如下;
functionq=myfun(p)
x=p
(1);
y=p
(2);
z=p(3);
q
(1)=sin(x)+y^2+log(z)-7;
q
(2)=3*x+2^y-z^3+1;
q(3)=x+y+z-5;
调用fsolve函数求根,命令如下;
options=optimset('
Display'
off'
x=fsolve(@myfun,[1,1,1]'
options)
(1)建立函数文件funt.m,命令如下;
functionyp=funt(t,y)
yp=-y*(1.2+sin(10*t));
求微分方程,程序如下:
>
t0=0;
tf=5;
y0=1;
[t,y]=ode23(@funt,[t0,tf],y0)
(2)建立函数文件funr.m,命令如下;
functionyp=funr(t,y)
yp=cos(t)-(y)/(1+t^2);
求微分方程,程序如下:
[t,y]=ode23(@funr,[t0,tf],y0)
4.
建立函数文件mymax.m命令如下:
functionfx=mymax(x)
fx=-1*(1+x^2)/(1+x^4);
求最大值,程序如下:
[x,y]=fminbnd(@mymax,0,2)
5.
编写目标函数M文件fop.m,命令如下:
functionf=fop(x)
f=-1*(x
(1)^(1/2)+x
(2)^(1/2)+x(3)^(1/2)+x(4)^(1/2));
设定约束条件,并调用fmincon函数求解此约束最优化问题,程序如下:
x0=[200,200,200,200];
A=[1,0,0,0;
1.21,1,0,0;
1.331,1.21,1,0;
1.4641,1.331,1.21,1];
b=[400,440,484,532.4];
Ib=[0,0,0,0];
options=optimset('
[x,y]=fmincon(@fop,x0,A,b,[],[],Ib,[],[],options)
1,
(1)矩阵求逆:
A=[2,3,5;
3,7,4;
1,-7,1];
b=[10,3,5]'
x=inv(A)*b
矩阵除法:
x=A\b
矩阵分解:
[L,U]=lu(A);
x=U\(L\b)
(2)矩阵求逆:
A=[6,5,-2,5;
9,-1,4,-1;
3,4,2,-2;
3,-9,0,2];
b=[-4,13,1,11]'
矩阵除法:
矩阵分解:
[L,U]=lu(A);
(1)建立函数文件fun1.m,命令如下:
functionfx=fun1(x)
fx=3*x+sin(x)-exp(x);
y=fzero(@fun1,1.5)
(2)建立函数文件fun2.m,命令如下:
functionfx=fun2(x)
fx=1-(1/x)+5;
y=fzero(@fun2,1)
(3)建立函数文件myfun3.m,命令如下;
functionq=fun3(p)
q
(1)=x^2+y^2-9;
q
(2)=x+y-1;
x=fsolve(@fun3,[1,1]'
(1)建立函数文件fun5.m,命令如下:
functionydot=fun5(t,y)
ydot
(1)=(2-3*y
(2)-2*t*y
(1))/(1+t^2);
ydot
(2)=y
(1);
ydot=ydot'
求解微分方程,命令如下:
x0=[0,1];
[t,y]=ode45(@fun5,[t0,tf],x0);
[t,y]
(2)
(1)建立函数文件fun5.m,命令如下:
functionydot=fun6(t,y)
ydot
(1)=cos(t)+(5*y
(1)*cos(2*t))/(t+1)^2-y
(2)-y(3)/(3+sin(t));
ydot(3)=y
(2);
建立函数文件max.m命令如下:
functionfx=max(x)
fx=-1*(sin(x)+cos(x^2));
[x,y]=fminbnd(@mymax,0,pi)
functionf=topm(x)
f=-1*x*(3-2*x)^2;
x0=[0];
A=[1];
b=[1.5];
Ib=[0];
[x,y]=fmincon(@top,x0,A,b,[],[],Ib,[],[],options)
第七章
1.functionf=f1(x)
f=sin(x)./x;
functionf=f2(x)
f=[1./((x-0.3).^2+0.01)-1./((x-0.9).^2+0.04)-6];
[I,n]=quad(@f1,0,2)
[S,n]=quad(@f2,0,1)
2.f=inline('
exp(-x.^2-y.^2)'
x'
y'
I1=dblquad(f,0,1,0,1)
f=inline('
abs(cos(x+y))'
I2=dblquad(f,0,pi,0,pi)
3.X=0.3:
0.2:
1.5;
Y=[0.3895,0.6598,0.9147,1.1611,1.3971,1.6212,1.8325];
trapz(X,Y)
4.x=0:
pi/5:
forn=1:
3
n
DX=diff(sin(x),n)
5.f=inline('
sin(x)./(x+cos(2.*x))'
g=inline('
[cos(x).*(x+cos(2.*x))-sin(x).*(1-2.*sin(2.*x))]./(x+cos(2.*x)).^2'
x=0:
p=polyfit(x,f(x),5);
dp=polyder(p);
dpx=polyval(dp,x);
dx=diff(f([x,2*pi+0.01]))/0.01;
gx=g(x);
plot(x,dpx,x,dx,'
-'
x,gx,'
:
1.求解定积分的数值方法有梯形法、辛普森法、高斯法等,基本思想是将整个积分区间分成n个子区间,而每个小的子区间上的定积分的值可近似求得。
任意函数在x点的导数是通过极限定义的,若去掉步长趋近于0的极限过程,引进向前差分向后差分的记号,当步长充分小时,导数等于差分与步长的商,即差商。
2.formatlong
fx=inline('
1./(1+x.^2)'
[I,n]=quad(fx,-10000,10000,1e-10)
[I,n]=quadl(fx,-10000,10000,1e-10)
x=-10000:
10000;
y=1./(1+x.^2);
trapz(x,y)
formatshort
3.formatlong
f1=inline('
log(1+x)./(1+x.^2)'
f2=inline('
sqrt(cos(t.^2)+4.*sin(4.*t.^2)+1)'
[I,n]=quad(f1,0,1)
[I,n]=quad(f2,0,2*pi)
4.fxyz=inline('
4.*x.*z.*exp(-z.^2.*y-x.^2)'
z'
triplequad(fxyz,0,pi,0,pi,0,1)
sin(x)'
g=inline('
cos(x)'
x=-pi:
p=polyfit(x,f(x),5);
dp=polyder(p);
dpx=polyval(dp,x);
dx=diff(f([x,pi+0.01]))/0.01;
gx=g(x);
plot(x,dpx,x,dx,'
.'
第八章
因式分解x^4-y^4
symsabxy;
A=x^4-y^4;
factor(A)
ans=
(x-y)*(x+y)*(x^2+y^2)
因式分解5135
x=sym('
5135'
B=factor(x)
B=
5*13*79
求极限
1>
symsx;
f=x-2/x^2-4;