西南交通大学数学实验参考答案.docx
《西南交通大学数学实验参考答案.docx》由会员分享,可在线阅读,更多相关《西南交通大学数学实验参考答案.docx(26页珍藏版)》请在冰豆网上搜索。
![西南交通大学数学实验参考答案.docx](https://file1.bdocx.com/fileroot1/2022-12/12/fc950be7-efb5-4baa-9151-f8be61c9c00c/fc950be7-efb5-4baa-9151-f8be61c9c00c1.gif)
西南交通大学数学实验参考答案
%sy1ljy20111514
%第一大题
%1
x=[3,2*pi];
y1=sin(x)+exp(x)
%y1=20.2267535.4917
%2
x=2:
2:
10
y2=x.^2+sqrt(2*x)
%x=246810
%y2=
6.000018.828439.464168.0000104.4721
%3
a=2*pi;b=35*pi/180;c=exp
(2)
y31=sin(a/5)+cos(b)*c
%c=
7.3891
%y2=
6.000018.828439.464168.0000104.4721
%4
Formalrational
%6
a=-6.28;a2=7.46;a3=5.37;
a11=fix(a1),a21=fix(a2),a31=fix(a3)
%7
y71=abs(a1*a2+a3)
y72=a1^2*sqrt(a2*a3/2)
Formalshort
%8
savesy2
clear
%9
loadsy1
%10
A=[2-56;831;-469]
A1=A’,A2=det(A),A3=5*A
savesy1A1A2A3
%第二大题
%1
X=0:
pi/10:
2*pi;
Y=cos(X);S=[X’,Y’]
%2
a22=input(‘a22=’);
b22=input(‘b22=’);
c22=input(‘c22=’);
s=(a22+b22+c22)/2;
A2=sqrt(s*(s-a22)*(s-b22)*(s-c22))
%3
sumjs=0;sumos=0;
fori=1:
2:
99
sumjs=sumjs+i;
sumos=sumos+i+1;
end
sumjs
sumos
%4
n=1000;i=1;k=1;
whilek<=n
ifrem(k,3)==2&rem(k,5)==3&rem(k,7)==2
a4(i)=k;
i=i+1;
end
k=k+1;
end
a4
a4=
23128233338443548653758863968
%sy2ljy20111514
%第一大题
%1.1
x1=[3,5,-1,2,8,12]
y1=3*x1.^2+exp(x1)-x1+2
y1
%1.2
x2=[-2,-1,0,1,2,3,4]
y2=(sin(x2+2)-1)/(x2^3+6)
y2
%第二大题
%2.1
x=input('x=')
ifx>=0
y1=2*x-sin(4*x)
else
y1=exp(x)+x.^3
end
%y1=12.5664y1=-1.7280e+003
%2.2
x=input('x=')
ifx>0
y2=5*x+3
elseifx<0
y2=3*x.^2
else
y2=4
end
%y2=228y2=3072
%第三大题
functiony3=f3(x)
ifx>0
y3=log(2*x)
else
y3=2*x.^3-x+5
end
%f3(4)=2.0794f3(0)=5f3(-2)=-9
%第四大题
%4.1
fori=1:
6
forj=1:
6
ifi==j
A4(i,j)=5;
elseifabs(i-j)==1
A4(i,j)=2;
else
A4(i,j)=1;
end
end
end
%4.2
A4
A(1,1)=3
A(1,2)=2
A(1,3)=5
A(1,4)=4
A(1,5)=-2
A(1,6)=-3
fori=2:
6
forj=1:
6
A(i,j)=A((i-1),j)*A(1,j)
end
end
A
%4.3
n=input('n=')
sum=0;k=1;
whilek<=n
sum=sum+1/k
k=k+1
end
sum
%sum=3.3182sum=3.5977
%4.4
a=[1,1];
fori=3:
40;
a=[a,a(i-2)+a(i-1)];
end
F=reshape(a,10,4)
%4.5
a=input('a=')
n=input('n=')
fori=2:
n
a=[a,a(i-1)+a
(1)*(10^(i-1))]
end
Sn=sum(a)
%5
score=input('成绩');
n=score/10
switchfix(n)
case{10,9}
disp('优秀');
case{8,7}
disp('良');
case6
disp('及格');
otherwise
disp('不及格');
end
%6
n=0;
form=1:
200;
flag=1;j=m-1;
i=2;
whilei<=j&flag
ifrem(m,i)==0
flag=0;
end
i=i+1;
end
ifflag
n=n+1;
prime(n)=m;
end
end
prime
%7
s=input('距离km')
p=input('每吨基本运费')
w=input('货物重')
switchs
case(s<250)
d=0;
case(s<500&s>=250)
d=0.02;
case(s<1000&s>=500)
d=0.05;
case(s<2000&s>=1000)
d=0.08;
case(s<3000&s>=2000)
d=0.1;
case(s>=3000)
d=0.15;
end
f=(1-d)*s*p*w
%sy3ljy20111514
%一大题
x11=[2-58-171-83259]
%1.2
x12=(2:
2:
22)
%1.3
x13=linspace(0,2*pi,20)
%1.4
x14=rand(1,8)
%1.5
x15=rand(6,1)
%1.6
x16=x11(abs(x11)>3)
%1.7
m1=[549];
m2=[863];
m=m1-m2;
a=norm(m)
%1.8
x18=4+x11+7*x12
%1.9
x19=x11*x12'
%1.10
x10=cross(x11([1,2,3]),x12([1,2,3]))
%2大题
%2.1
figure
axis([0808]);
x=[2442246642244664];
y=[5533555333113311];
line(x,y)
%2.2
figure
y=[4553235678];
plot(y)
%2.3
figure
x23=(0.1:
0.01:
10);
y23=30./x23;
plot(y23)
%2.4
figure
x24=linspace(-5,5,30);
y24=5*x24.*cos(x24);
plot(y24)
%2.5
figure
x25=linspace(-2*pi,2*pi,50);
y25=sin(x25);
plot(y25)
holdon
z25=cos(x25);4;
plot(z25,'r--');
holdoff
%2.6
subplot(2,3,1);
fplot('3*x^2',[-8,8]);
title('f1=3x^2');
subplot(2,3,2);
fplot('exp(x+1)',[-8,8]);
title('f2=e^(x+1)')
%3.1
t=linspace(-2,2,50)*pi;
a=input('a=');
b=input('b=');
x=a*cos(t);y=b*sin(t);
plot(x,y,'r');
axisequal
text(-0.5,0,'x^2/a^2+y^2/b^2=1');
%3.2
t=linspace(0,4*pi,50)
r=cos(t/3);
subplot(1,3,1)
plot(t,r);
holdon
t=linspace(0,5*pi,50)
r=exp(0.3*t);
subplot(1,3,2)
plot(t,r);
holdon
t=linspace(0.6*pi,6*pi,50)
r=4./t;
subplot(1,3,3)
plot(t,r);
holdoff
%3.3
t=0:
pi/12.5:
8*pi;
plot3(sin(t),cos(t),t);
label('x'),ylabel('y')
%sy4wangchao20121652
%1.1
t=1:
0.5:
10;
r=2+cos(t)+sin(t);
cylinder(r,30)
title('旋转抛物面图');
%1.2
[x,y]=meshgrid(-3:
0.5:
3);
z2=x.*y;
mesh(x,y,z2);
title('双曲抛物面');
%1.3
[x,y]=meshgrid(-5:
0.5:
5);
z3=sqrt(abs(x.^2-2.*y));
surf(x,y,z3);
title('曲面表面图');
%1.4
function[xx,yy,zz]=sphere(n);
ifnargin==0,n=20;end;
theta=(-n:
2:
n)/n*pi;
phi=(-n:
2:
n)'/n*pi/2;
cosphi=cos(phi);cosphi
(1)=0;cosphi(n+1)=0;
sintheta=sin(theta);sintheta
(1)=0;sintheta(n+1)=0;
x=cosphi*cos(theta);
y=cosphi*sintheta;
z4=cos(phi).^2*ones(1,n+1).^2;
surf(x,y,z4)
shadinginterp
%1.5
ezsurf(@(x,y)(x^2+y^2+6*sin(2*x)),[-2*pi2*pi-2*pi2*pi])
shadinginterp
%2.1
x21=1:
1:
10;
y21=fix(rand(1,10)*30);
bar(x21,y21)
%2.2
y221=[2.534.552.8];
y222=[22.232.51.8];
x=1:
5;
area(x,y221,'facecolor',[0.750.60.9],'edgecolor','b');
holdon;
area(x,y222,'facecolor',[0.50.90.7],'edgecolor','r');
holdoff;
gtext('五年某地区住房修建统计')
gtext('入住率')
%2.3
y22=fix(rand(1,50)*30);
hist(y22,5)
%2.4
y23=[46751482149835];
pie3(y23,[000100])
%2.5
[x,y,z]=peaks(30);
subplot(2,2,1)
surf(x,y,z)
subplot(2,2,2)
contour(x,y,z,15)
%3
(1)
sc1=[562131272126562432]
sc2=[361931405129101310]
sc3=[451231424953114]
sc4=[491519426293244]
subplot(2,2,1)
pie3(sc1)
subplot(2,2,2)
pie3(sc2)
subplot(2,2,3)
pie3(sc3)
subplot(2,2,4)
pie3(sc4)
%
(2)
x=1:
9;
sc1=[562131272126562432]
sc2=[361931405129101310]
sc3=[451231424953114]
sc4=[491519426293244]
subplot(2,2,1)
bar(x,sc1)
subplot(2,2,2)
bar(x,sc2)
subplot(2,2,3)
bar(x,sc3)
subplot(2,2,4)
bar(x,sc4)
%4.1
t=-5*pi:
pi/200:
5*pi;
comet(sin(t),t.*cos(t))
%4.2
t=0:
0.01:
100;
x=2*t.^2;
y=2*sin(t);
z=5*cos(3*t);
comet3(x,y,z)
%sy5wmy20111510
%1.1
a1=[1357;2468;9863;-6043]
%1.2
a2=[35-23;4830;674-1;2569]
%1.3
a3=sym('[x*1x*2x*3x*4x*5;y*1y*2y*3y*4y*5]')
a4=sym('[sin(x)x^2;1+xcos(x)]')
b=fix(rand(4,4)*20)
%1.4
t=[234253]
f1=vander(t)
f=rot90(f1)
%1.5
c=magic(4)
%1.6
q=zeros(4,4)
e=eye(4)
n=ones(4,4)
%1.7
a6=[beq;nca1]
%2.1.1
a1=[1357;2468;9863;-6043]
a21=max(a1)
[xy]=find(a1==max(max(a1)))
%2.1.2
a1=[1357;2468;9863;-6043]
a22=min(a1)
[xy]=find(a1==min(min(a1)))
%2.1.3
a1=[1357;2468;9863;-6043]
a23=mean(a1)
a24=median(a1)
%2.1.4
a1=[1357;2468;9863;-6043]
a25=std(a1)
a26=sum(a1)
%2.2
a1=[1357;2468;9863;-6043]
a2=[35-23;4830;674-1;2569]
a27=a1+a2
a28=a1*a2
%2.3
a2=[35-23;4830;674-1;2569]
a29=a2([1,3],[2,3])
%3.1
a=fix(rand(6,6)*20)
%3.2
a31=a'
a34=det(a)
a33=rank(a)
%3.3
a=fix(rand(6,6)*20)
a34=inv(a)
%3.4
a=fix(rand(6,6)*20)
[d,x]=eig(a)
%4.1
a=[1-52-3;536-1;2421]
b=[11;-1-6]
a1=[ab]
ifrank(a1)==rank(a)
rr=rref(a1)
%5
m=[110;11-1;0-14]
[d,x]=eig(m)
p=orth(d)
y=p^(-1)*x
%f=-0.1284*y1^2+1.7984*y2^2+4.3301*y3^2
%6.1
[a21,x]=max(a21
c1=[4262758];
p1=poly2sym(c1)
%6.2
c2=[1,4,7]
c22=poly(c2)
p2=poly2sym(c22)
%6.3
c3=[1-24-6]
r=root(c3)
%6.4
c4=[1-9211-30]
r=roots(c4)
%6.5
c51=[104-309]
c52=[1-648]
f1=poly2sym(c51)
f2=poly2sym(c52)
g1=f1+f2
gp2=conv(c51,c52)
g2=poly2sym(gp2)
[q,r]=deconv(c51,c52)
%6.6
c66=[35-246-71]
p66=polyder(c66)
f6=poly2sym(p66)
%6.7
c=[1-78-69]
x=[3,2,1]
y=polyval(c,x)
%6.8
x=1:
2:
15;
y=[1.9221-1.8389-0.39162.1648-1.4101-0.99112.2351-0.8691]
c=polyfit(x,y,6)
z=polyval(c,x)
plot(x,y,'ro-',x,z,':
')
%第一大题
%1
x=input('x=');
ifx>0
f1=4*x^3+5*sqrt(x)-7;
elsef1=x^2+sin(x);
end
f1
%f1(12)=6.9223e+003
%f1(-32)=1.0234e+003
%2
functiony=f2(x)
ifx<0
y=sin(5*x)+6*x^3;
elsey=x^2+sin(x);
end
%f2(-6)=-1.2950e+003
%f2(11)=120.0000
%3
symsx
f3=(1+x)/(x-3)
g=finverse(f3)
%f3=(1+x)/(x-3)
%g=(1+3*x)/(-1+x)
%4
symsx
f4=3*x^4+5*x^3-6*x^2+7;
g4=8*x^3+2*x^2+x-9;
u1=f4+g4
u2=f4-g4
u3=f4*g4
u4=f4/g4
u5=f4^g4
u6=compose(f4,g4)
%u1=3*x^4+13*x^3-4*x^2-2+x
u2=3*x^4-3*x^3-8*x^2+16-x
u3=(3*x^4+5*x^3-6*x^2+7)*(8*x^3+2*x^2+x-9)
u4=(3*x^4+5*x^3-6*x^2+7)/(8*x^3+2*x^2+x-9)
u5=(3*x^4+5*x^3-6*x^2+7)^(8*x^3+2*x^2+x-9)
u6=3*(8*x^3+2*x^2+x-9)^4+5*(8*x^3+2*x^2+x-9)^3-6*(8*x^3+2*x^2+x-9)^2+7
%5
symsx
f5=-452*x^2+224*x^3+60*x^4-296*x+320;
f51=factor(f5)
f52=horner(f5)
r5=solve(f5)
%f51=4*(5*x-8)*(3*x-2)*(x+5)*(1+x)
%f52=320+(-296+(-452+(224+60*x)*x)*x)*x
%r5=-12/3-58/5
%6
g6='x*exp(x)-2*x^2+5';
x=fzero(g6,[-2.2])
%x=-1.5278
%第二大题
%1
symsx
y1=(x^2)*(3^(1/x)+3^(-1/x)-2);
y11=limit(y1,inf)
%y11=log(3)^2
%2
y21=limit(x*log(sin(x)),x,0,'right')
y22=limit((sin(sqrt(x^2+1))-sin(x))/x,inf)
%y21=0y22=0
%3
f=sin(x);
y31=taylor(f,5,1)
%y31=sin
(1)+cos
(1)*(-1+x)-1/2*sin
(1)*(-1+x)^2-1/6*cos
(1)*(-1+x)^3+1/24*sin
(1)*(
%-1+x)^4
%第三大题
symsx
f32=limit(exp(x)+x,x,0,'right');
f33=limit(x^2+1,x,0,'left');
if(f32==f33)&(f32==1)
a='函数在分界点连续'
else
a='函数在分界点不连续'
end
%a=函数在分界点连续
%第四大题
%1
f41=sin(x^3);
f410=diff(f41,x,1)
%f410=3*cos(x^3)*x^2
%2
f42=x^(1/a)+a^(1/x)+x^(1/x);
f420=diff(f42,x,2)
%f420=x^(1/a)/a^2/x^2-x^(1/a)/a/x^2+a^(1/x)/x^4*log(a)^2+2*a^(1/x)/x^3*log(a)+x^(1/x)*(-1/x^2*log(x)+1/x^2)^2+x^(1/x)*(2/x^3*log(x)-3/x^3)
%3
f43=atan(log(x));
f430=diff(f43,x,2)
%f430=-1/x^2/(1+log(x)^2)-2/x^2/(1+log(x)^2)^2*log(x)
%4
f44=x*asin(x)/sqrt(1-x^2)+log(1-x^2);
f440=diff(f44,x,2)
%f440=3*asin(x)/(1-x^2)^(3/2)*x-x^2/(1-x^2)^2+3*x^3*asin(x)/(1-x^2)^(5/2)
%第五大题
%1
symsx;
f51='2*x^3-6*x^2-18*x+7';
[x,minf51]=fminbnd(f51,1,2)
%x=1.9999minf51=-36.9988
%2
symsx;
[x,maxf52]=fminbnd('-x-sqrt(16-x)',-2,2);
maxf52=-maxf52
x
%maxf52=5.7416
x=1.9999
%第六大题
%1
symsx;
f='(x^5)*cos(x^3)';
y61=int(f)
%y61=cos(x^3)/3+(x^3*sin(x^3))/3
%2
symsx;
f='(sin(x))^10';
y62=int(f)
%y62=(63*x)/256-(105*sin(2*x))/512+(15*sin(4*x))/256-
%(15*sin(6*x))/1024+(5*sin(8*x))/2048-sin(10*x)/5120
%3
symsx;
f='1/(((x+1)^2)*((x+1)^4))^(1/3)';
y63=int(f)
%y63=-(x+1)/((x+1)^6)^(1/3)
%第七大题