《MATLAB及其在大学物理课程中地指导应用》习题问题详解___电子科大__第二版
第二章
1、
x=[2,4];
y=x.^3+(x-0.98).^2./(x+1.35).^3-5*(x+1./x)
2、
y=cos(pi/3)-(9-sqrt(2))^(1/3)
3、
a=3;A=4;
b=a.^2;
B=b.^2-1;
c=a+A-2*B;
C=a+2*B+c
4、x=[1 2 3;4 5 6;7 8 9]
Desktop->Workspace,双击变量x
5、
clear
x=magic(3)
y=randn(3,3)
xy=[x,y]
yx=[x,y]
z=xy(:,1:2)
6、
clear
x=eye(4,4)
y=triu(x)
7、
x=rand(4,5)
y=x([1,2],:)
z=(y>=0.3).*y
8、
clear
x=randn(5,5)
y=inv(x)
9、
clear
x=randn(5,5)
z=x^5
10、
clear
A=[1,4,8;-3,6,-5;2,-7,-12];
B=[5,4,3;6,-2,3;-1,3,-9];
C=A*B
D=A.*B
11、
clear
x=linspace(0,2*pi,125);
y=cos(x).*(0.5+3*sin(x)./(1+x.^2)); plot(x,y)
z=-45:1:45;
x=z.*sin(3*z);y=z.*cos(3*z);
plot3(x,y,z);
13、
x=-2:0.1:2,y=x;
[x,y]=meshgrid(x,y);
z=x.^2.*exp(-x.^2-y.^2)
surf(x,y,z);
14、
x=-2:0.1:2,y=x;
[x,y]=meshgrid(x,y);
z=x.^2.*exp(-x.^2-y.^2);
surf(x,y,z);
z1=0.05*x-0.05*y+0.1;
hold on,mesh(x,y,z1);
15、
(1)
n=2;alfa=0;
t=0:0.1:10;x=cos(t);y=sin(n*t+alfa); subplot(2,2,1);plot(t,x,t,y);
(2)
n=2;alfa=0;
t=0:0.1:10;x=cos(t);y=sin(n*t+alfa); subplot(2,2,1);plot(t,x,t,y);
n=2;alfa=pi/3;
t=0:0.1:10;x=cos(t);y=sin(n*t+alfa); subplot(2,2,2);plot(t,x,t,y);
n=2;alfa=pi/2;
t=0:0.1:10;x=cos(t);y=sin(n*t+alfa);
subplot(2,2,3);plot(t,x,t,y);
n=2;alfa=pi;
t=0:0.1:10;x=cos(t);y=sin(n*t+alfa);
subplot(2,2,4);plot(t,x,t,y);
球体
clear
for i=1:100
for j=1:100
x(i,j)=i/100*cos(j*2*pi/100);
y(i,j)=i/100*sin(j*2*pi/100);
z(i,j)=sqrt(1.001-x(i,j)^2-y(i,j)^2);
end
end
surf(x,y,z);hold on;surf(x,y,-z);axis equal
棱锥
clear
for i=1:100
for j=1:100
x(i,j)=i/100*cos(j*2*pi/4);
y(i,j)=i/100*sin(j*2*pi/4);
z(i,j)=sqrt(x(i,j)^2+y(i,j)^2);
end
end
surf(x,y,-z);
求最大值
x=[67 87 56 99 43] max=0;
for i=1:5
if max>=x(i)
max=max;
else max=x(i)
end
end
max
求最小值
x=[67 87 56 99 43] min=inf;
for i=1:5
if min<=x(i)
min=min;
else min=x(i)
end
end
min
求和
x=[67 87 56 99 43]; sum=0;
for i=1:5
sum=sum+x(i) end
sum
第三章
1、
h0=[446,714,950,1422,1634];
t0=[7.04,4.28,3.40,2.54,2.13];
t1=interp1(h0,t0,500,'linear')
2、
x0=[1,0,-1];y0=[0,1,0];
p=polyfit(x0,y0,3);
x=-1:0.1:1;
y=polyval(p,x);
plot(x,y,-x,-y),axis equal
3、
clear
x0=[1.0,1.1,1.2,1.3,1.4];
y0=[0.25,0.2268,0.2066,0.1890,0.1736]; p=polyfit(x0,y0,3);
p1=polyder(p);
y=polyval(p1,[1.0,1.2])
4、
p=[3 4 7 2 9 12];
r=roots(p)
5、
r=[-3 -5 -8 -9];
p=poly(r)