精讲多练MATLAB课后习题答案.docx
《精讲多练MATLAB课后习题答案.docx》由会员分享,可在线阅读,更多相关《精讲多练MATLAB课后习题答案.docx(11页珍藏版)》请在冰豆网上搜索。
精讲多练MATLAB课后习题答案
第1章练习题答案
1-2.
A=1.2;B=-4.6;C=8.0;D=3.5;E=-4.0;
T=atan((2*pi*A+E/(2*pi*B*C))/D)
1-3
clear
x=45;
(sin(x*pi/180)+sqrt(35))/(72^(1/5))
1-4
clear
a=5.67;b=7.811;
exp(a+b)/log10(a+b)
1-5
clear
x=3;
y=sqrt(x)-6*(x+1/x)+(x-3.2)^2/(x+7.7)^3
1-6
clear
r=15;
d=2*r
c=2*pi*r
s=pi*r*r
1-7
clear
a=8.5;b=14.6;c=18.4;
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c))
第2章练习题答案
2-1clear
A=[311;212;123];
B=[11-1;2-10;1-11];
2*A+B,4*(A^2)-3*(B^2),A*B,B*A,A*B-B*A
2-2clear
A=[1/300;01/40;001/7];
B=inv(inv(A)-eye(3))*6
2-3clear
B=[12-3-2;012-3;0012;0001];
C=[1201;0120;0012;0001];
A=(inv(2*eye(4)-inv(C)*B)*inv(C))'
2-4clear
A=[2-1;-12];
B=[0-2;-20];
X=(1/2)*(B+2*A)
2-5clear
A=[2-302;1521;3-11-1;4122];
B=[8;2;7;12];
X=A\B
2-6A=[31247081];
p=poly2str(A,'x')
x=roots(A)
2-7A=[31247081];
B=[1-35-150];
[div,rest]=deconv(A,B)
第三章
3-1.x=sym('x');
limit((cos(sqrt(x)))^(pi/x),x,0,'right')
ans=exp(-1/2*pi)
3-2.x=sym('x');
f=sym('(3*sin(x)+x^2*cos(1/x))/((1+cos(x))*log(1+x))');
limit(f,x,0)
ans=3/2
3-3.x=sym('x');
f=sym('(sqrt(4*x^2+x-1)+x+1)/sqrt(x^2+sin(x))');
limit(f,x,-inf)
ans=1
3-4.symsxy;
f=sym('(x^2+y^2)^(x^2*y^2)');
limit(limit(f,x,0),y,0)
ans=1
3-5.x=sym('x');
y=sym('(tan(sqrt(x+sqrt(x+sqrt(2*x)))))^2');
diff(y,x)
ans=tan((x+(x+2^(1/2)*x^(1/2))^(1/2))^(1/2))*(1+tan((x+(x+2^(1/2)*x^(1/2))^(1/2))^(1/2))^2)/(x+(x+2^(1/2)*x^(1/2))^(1/2))^(1/2)*(1+1/2/(x+2^(1/2)*x^(1/2))^(1/2)*(1+1/2*2^(1/2)/x^(1/2)))
3-6.
x=sym('x');
y=sym('cos(x^2)*sin(1/x)^2');
diff(y,x)
ans=-2*sin(x^2)*x*sin(1/x)^2-2*cos(x^2)*sin(1/x)*cos(1/x)/x^2
3-7.
x=sym('x');
y=sym('sqrt(sin(x)-sin(x)^3)');
int(y,x,0,pi)
ans=4/3
3-8.x=sym('x');
y=sym('sqrt((x+1)/(x-1))/x');
int(y,x)
ans=-((1+x)/(x-1))^(1/2)*(x-1)*(atan(1/(-1+x^2)^(1/2))-log(x+(-1+x^2)^(1/2)))/((1+x)*(x-1))^(1/2)
3-9.dsolve('D2y+4*Dy+4*y=exp(-2*x)','x')
ans=
1/2*exp(-2*x)*(2*C2+2*x*C1+x^2)
3-10.
dsolve('x^2*Dy+x*y=y^2','y
(1)=1')
ans=x*exp(1/x)/(exp(1/x)+exp(1/x*t)*x-exp(1/x*t))
第四章
4-1.
plot([1240510112131])
4-2.
t=0:
pi/100:
2*pi;
x=cos(t);
y=sin(t);
plot(x,y);
axis('square');
4-3.
R=[151020];
I=0:
0.1:
10;
U=I'*R;
plot(I,U);
4-4.
mon=1:
12;
temp=[0.22.38.718.524.632.136.837.128.317.86.4-3.2];
rainf=[4.63.62.12.93.02.72.22.54.33.42.13.7];
plot(mon,temp,'r-p',mon,rainf,'b:
s');
xlabel('month');
ylabel('temperatureandrainfall');
%title('TemperatureandRainfallCurve');
%text(3,1,'rainfall');
%text(9,28.3,'temperature');
flag=12;
while(flag)
text(mon(flag),temp(flag),[num2str(mon(flag)),num2str(temp(flag))]);
text(mon(flag),rainf(flag),[num2str(mon(flag)),num2str(rainf(flag))]);
flag=flag-1;
end
4-5.
A=[1111111;1222221;1223221;1222221;1111111];
plot(A);
4-6.
x=-10:
0.5:
10;
y=x;
[X,Y]=meshgrid(x,y);
Z=X.^2+Y.^2;
surf(X,Y,Z);
4-7.
clc
clear
theta=(0:
0.1:
2)*pi;
phi=(0:
0.1:
2)*pi;
x=zeros(length(theta),length(phi));
y=x;
z=x;
fori=1:
length(theta)
forj=1:
length(phi)
x(i,j)=2*sin(theta(i))*cos(phi(j));
y(i,j)=3*sin(theta(i))*sin(phi(j));
end
z(i,:
)=4*cos(theta(i));
end
axissquare
subplot(2,2,1);
mesh(x,y,z)
title('三维')
subplot(2,2,2);
mesh(x,y,z)
view(90,0)
title('X轴视图')
subplot(2,2,3);
mesh(x,y,z)
view(0,0)
title('Y轴视图')
subplot(2,2,4);
mesh(x,y,z)
view(0,90)
title('Z轴视图')
第五章
5-1:
clear;
x=-2:
0.01:
2;
forii=1:
401
if(x(ii)<0)
y(ii)=x(ii)+1;
elseif(x(ii)<1)&(x(ii)>=0)
y(ii)=1;
elseif(x(ii)>=1)
y(ii)=x(ii)^3;
end
end
plot(x,y);
5-2:
functiony=fenduan(x)
if(x<0)
y=x+1;
elseif(x<1)&(x>=0)
y=1;
elseif(x>=1)
y=x^3;
end
5-3:
建立文件arcsin.m如下:
functiony=arcsin(x)
ifabs(x)>1
disp('输入参数绝对值必须小于1');
return;
end
n=0;
y=0;
u=x;
whileu>eps
u=(jiecheng(2*n)*x^(2*n+1))/(2^(2*n)*(jiecheng(n)^2*(2*n+1)));
y=y+u;
n=n+1;
end
建立文件jiecheng.m如下:
functiony=jiecheng(n)
if(n<0)
disp('输入参数必须为大于或等于0整数');
return;
end
ifn==0|n==1
y=1;
else
y=n*jiecheng(n-1);
end
5-4:
建立shuliang.m文件如下:
function[tu,ji]=shuliang(tou,jiao)
tu=jiao/2-tou;
ji=2*tou-jiao/2;
在命令窗口中执行:
>>[a,b]=shuliang(36,100)
5-5:
fori=2:
999
ge=rem(i,10);
shi=rem(fix(i/10),10);
bai=fix(i/100);
ifrem((ge+shi+bai),2)&isprime(i)
disp(i);
end
end
5-6:
functiony=issushu(n)
y=1;
forii=2:
fix(n/2)
if(rem(n,ii)==0)
y=0;
end
end
习题1(程序段后面是其运行结果)
例题1.2
function lt12 a=1+2*i;b=3-4*i;
disp(['a+b=',num2str(a+b)]) disp(['a-b=',num2str(a-b)]) disp(['a*b=',num2str(a*b)]) disp(['a/b=',num2str(a/b)]) >> lt12 a+b=4-2i a-b=-2+6i a*b=11+2i
a/b=-0.2+0.4i >>
例题1.3
function z=lt13
x=(-3.5)*pi/180;y=6.7*pi/180;
z=sin(abs(x)+abs(y))/sqrt(cos(abs(x+y))); >> lt13
ans =
0.1772 >>
例题1.4
function p1=lt14
r=0.0107;n=2015-2000;p0=12.9533E8; p1=p0*(1.0+r)^n; >> lt14
ans =
1.5195e+009 >>
例题1.5
function lt15 a=1;b=2;c=3;
d=sqrt(b^2-4*a*c);
x1=(-b+d)/2*a;x2=(-b-d)/2*a; disp('原方程根是:
')
disp(['x1=',num2str(x1)]) disp(['x2=',num2str(x2)])
>> lt15
原方程根是:
x1=-1+1.4142i x2=-1-1.4142i >>