Matlab实验内容.docx

上传人:b****5 文档编号:7880566 上传时间:2023-01-26 格式:DOCX 页数:39 大小:1.71MB
下载 相关 举报
Matlab实验内容.docx_第1页
第1页 / 共39页
Matlab实验内容.docx_第2页
第2页 / 共39页
Matlab实验内容.docx_第3页
第3页 / 共39页
Matlab实验内容.docx_第4页
第4页 / 共39页
Matlab实验内容.docx_第5页
第5页 / 共39页
点击查看更多>>
下载资源
资源描述

Matlab实验内容.docx

《Matlab实验内容.docx》由会员分享,可在线阅读,更多相关《Matlab实验内容.docx(39页珍藏版)》请在冰豆网上搜索。

Matlab实验内容.docx

Matlab实验内容

Matlab实验内容

第1章

1.用help命令可以查询到自己的工作目录。

输入help命令:

help<函数名>

2.MATLAB的主要优点:

通过例1-1至例1-4的验证,MATLAB的优点是MATLAB以矩阵作为数据操作的基本单位,使得矩阵运算变得非常简捷,方便,高效。

还提供了丰富的数值计算函数。

MATLAB绘图十分方便,只需输入绘图命令,MATLAB便可自动绘出图形。

3.INV(X)istheinverseofthesquarematrixX。

AwarningmessageisprintedifXisbadlyscaledornearlysingular.PLOT(X,Y)plotsvectorYversusvectorX.IfXorYisamatrix,thenthevectorisplottedversustherowsorcolumnsofthematrix,whicheverlineup.IfXisascalarandYisavector,length(Y)disconnectedpointsareplotted.PLOT(Y)plotsthecolumnsofYversustheirindex.IfYiscomplex,PLOT(Y)isequivalenttoPLOT(real(Y),imag(Y)).InallotherusesofPLOT,theimaginarypartisignored.Forvectors,MAX(X)isthelargestelementinX.Formatrices,

MAX(X)isarowvectorcontainingthemaximumelementfromeachcolumn.ForN-Darrays,MAX(X)operatesalongthefirstnon-singletondimension.[Y,I]=MAX(X)returnstheindicesofthemaximumvaluesinvectorI.Ifthevaluesalongthefirstnon-singletondimensioncontainmorethanonemaximalelement,theindexofthefirstoneisreturned.ROUND(X)roundstheelementsofXtothenearestintegers.MAX(X,Y)returnsanarraythesamesizeasXandYwiththelargestelementstakenfromXorY.Eitheronecanbeascalar。

[Y,I]=MAX(X,[],DIM)operatesalongthedimensionDIM.Whencomplex,themagnitudeMAX(ABS(X))isused,andtheangleANGLE(X)isignored.NaN'sareignoredwhencomputingthemaximum.

4.sinx是以步长为∏/10,起始值为0,终止值为2∏的正弦函数。

5.MATLAB是一种用于数值计算、可视化及编程的高级语言和交互式环境。

使用MATLAB,可以分析数据,开发算法,创建模型和应用程序。

借助其语言、工具和内置数学函数,您可以探求多种方法,比电子表格或传统编程语言(如C/C++或Java™)更快地求取结果。

第2章

1.

(1)w=sqrt

(2)*(1+0.34245*10^(-6))

w=1.4142

(2)a=3.5;

b=5;

c=-9.8;

x=(2*pi*a+(b+c)/(pi+a*b*c)-exp

(2))/(tan(b+c)+a)

x=0.9829

(3)a=3.32;

b=-7.9;

y=2*pi*a^2*((1-pi/4)*b-(0.8333-pi/4)*a)

y=-128.4271

(4)t=[2,1-3i;5,-0.65];

z=0.5*exp(2*t)*log(t+sqrt(1+t*t))

z=

1.0e+004*

0.0048+0.0002i0.0048-0.0034i

1.58992.0090-1.3580i

2.

(1)A+6B=[47,23,-10;12,37,26;-15,73,7;]

A^2-B+I=[18,-216,18;23,533,110;22,868,526]

(2)A*B=[14,14,16;-10,51,21;125,328,180]

A.*B=[-8,15,4;0,35,24;-9,122,0]

B*A=[-11,0,-15;7,228,533,-1,28]

(3)A/B=[1.2234,-0.925,2.9787;-0.9468,2.3511,-0.9574;4.6170,3.8723,13.8936]

B\A=[-0.5106,-8.6170,-1.1277;0.7340,17.5745,1.8085;-0.8830,-21.2128,0.4043]

(4)[A,B]=[-1,5,-4,8,3,-1;0,7,8,2,5,3;3,61,7,-3,2,0]

[A([1,3],:

);B^2]=[-1,5,4;3,6,7;73,37,1;17,7,3;-20,1,9]

3.

(1)A=[2310-0.7780;41-45655;325032;6-9.54543.14]

A=

23.000010.0000-0.77800

41.0000-45.000065.00005.0000

32.00005.0000032.0000

6.0000-9.540054.00003.1400

B=A(1:

3,:

B=

23.000010.0000-0.77800

41.0000-45.000065.00005.0000

32.00005.0000032.0000

C=A(:

1:

2)

C=

23.000010.0000

41.0000-45.0000

32.00005.0000

6.0000-9.5400

D=A(2:

4,3:

4)

D=

65.00005.0000

032.0000

54.00003.1400

E=B*C

E=

1.0e+003*

0.9141-0.2239

1.20802.7123

1.1330-0.2103

(2)E

ans=

01

00

01

E&D

ans=

11

01

11

E|D

ans=

11

11

11

~D

ans=

00

10

00

~E

ans=

00

00

00

4.H=hilb(5);

P=pascal(5);

Hh=det(H)

Hh=3.7493e-012

Hp=det(P)

Hp=1

Th=cond(H)

Th=4.7661e+005

Tp=cond(P)

Tp=8.5175e+003

条件数越趋近于1,矩阵的性能越好,所以帕斯卡矩阵性能更好。

5.A=[-29,6,18;20,5,12;-8,8,5]

A=

-29618

20512

-885

[V,D]=eig(A)

V=

0.71300.28030.2733

-0.6084-0.78670.8725

0.34870.55010.4050

D=

-25.316900

0-10.51820

0016.8351

V为A的特征向量,D为A的特征值。

它们之间满足A*V=V*D

第3章

1.

n=input(‘请输入一个三位数:

’);

a=fix(n/100);

b=fix((n-a*100)/10);

c=n-a*100-b*10;

d=c*100+b*10+a

2.

(1)

n=input('请输入成绩');

switchn

casenum2cell(90:

100)

p='A';

casenum2cell(80:

89)

p='B';

casenum2cell(70:

79)

p='C';

casenum2cell(60:

69)

p='D';

otherwise

p='E';

end

price=p

(2)n=input('请输入成绩');

ifn>=90&n<=100

p='A';

elseifn>=80&n<=89

p='B';

elseifn>=70&n<=79

p='C';

elseifn>=60&n<=69

p='D';

else

p='E';

end

price=p

(3)try

n;

catch

price='error'

end

3.

(1)方法一:

n=[1,5,56,4,3,476,45,6,3,76,45,6,4,3,6,4,23,76,908,6];

a=n

(1);

b=n

(1);

form=2:

20

ifn(m)>a

a=n(m);

elseifn(m)

b=n(m);

end

end

max=a

min=b

(2)方法二:

n=[1,5,56,4,3,476,45,6,3,76,45,6,4,3,6,4,23,76,908,6];

min=min(n)

max=max(n)

4.

b=[-3.0:

0.1:

3.0];

forn=1:

61

a=b(n);

y(n)=(exp(0.3*a)-exp(-0.3*a))/2*sin(a+0.3)+log((0.3+a)/2);

end

y

5.

y1=0;

y2=1;

n=input('请输入n的值:

');

fori=1:

n

y1=y1+1/i^2;

y2=y2*((4*i*i)/((2*i-1)*(2*i+1)));

end

y1

y2

6.

A=[1,1,1,1,1,1;2,2,2,2,2,2;3,3,3,3,3,3;4,4,4,4,4,4;5,5,5,5,5,5;6,6,6,6,6,6];

n=input('请输入n的值:

');

ifn<=5&n>=0

disp(A([n],:

));

elseifn<0

disp(lasterr);

elsedisp(A([6],:

));

disp(lasterr);

end

7.

(1)

f=[];

forn=1:

40

f(n)=n+10*log(n^2+5);

end

y=f(40)/(f(30)+f(20))

(2)

f=[];a=0;

forn=1:

40

f(n)=a+n*(n+1);

a=f(n);

end

y=f(40)/(f(30)+f(20))

8.

y=0;

m=input('输入m的值:

');

n=input('输入n值:

');

fori=1:

n

y=y+i^m;

end

y

****************************************************

functions=shi8_1(n,m)

s=0;

fori=1:

n

s=s+i^m;

end

****************************************************

shi8_1(100,1)+shi8_1(50,2)+shi8_1(10,1/2)

第4章

1.

(1)

x=-10:

0.05:

10;

y=x-x.^3./6;

plot(x,y)

 

(2)

x=-10:

0.5:

10;

ezplot('x^2+2*y^2-64',[-8,8]);

gridon;

2.

t=-pi:

pi/10:

pi;

y=1./(1+exp(-t));

subplot(2,2,1);bar(t,y);

title('条形图(t,y)');

axis([-pi,pi,0,1]);

subplot(2,2,2);

stairs(t,y,'b');

title('阶梯图(t,y)');

axis([-pi,pi,0,1]);

subplot(2,2,3);

stem(t,y,'k');

title('杆图(t,y)');

axis([-pi,pi,0,1]);

subplot(2,2,4);

loglog(t,y,'y');

title('对数坐标图(t,y)');

3.

(1)

t=0:

pi/50:

2*pi;

r=5.*cos(t)+4;

polar(t,r);

title('\rho=5*cos\theta+4');

 

(2)

t=-pi/3:

pi/50:

pi/3;

r=5.*((sin(t)).^2)./cos(t);

polar(t,r);

 

4.

(1)

t=0:

pi/50:

2*pi;

x=exp(-t./20).*cos(t);

y=exp(-t./20).*sin(t);

z=t;

plot3(x,y,z);

gridon;

(2)

[x,y]=meshgrid(-5:

5);

z=zeros(11)+5;

mesh(x,y,z);

shadinginterp;

5

[x,y,z]=sphere(20);

surf(x,y,z);

axisoff;

shadinginterp;

m=moviein(20);

fori=1:

20

axis([-i,i,-i,i,-i,i])

m(:

i)=getframe;

end

movie(m,4);

第5章

1.

A=randn(10,5)

x=mean(A)

y=std(A)

Max=max(max(A))

Min=min(min(A))

Sumhang=sum(A,2)

SumA=sum(Sumhang)

B=sort(A);

C=sort(B,2,'descend');

C

2.

(1)

a=0:

15:

90;

b=a./180.*pi;

s=sin(b)

c=0:

15:

75;

d=c./180.*pi;

t=tan(d)

e=input('请输入想计算的值:

');

S=sin(e/180*pi)

T=tan(e/180*pi)

S1=interp1(a,s,e,'spline')

T1=interp1(c,t,e,'spline')

P1=polyfit(a,s,5);

P2=polyfit(c,t,5);

S2=polyval(P1,e)

T2=polyval(P2,e)

(2)

n=[1,9,16,25,36,49,64,81,100];

N=sqrt(n);

x=input('jisuanzhi:

');

interp1(n,N,x,'cubic')

3.

N=64;

T=5;

t=linspace(0,T,N);

h=exp(-t);

dt=t

(2)-t

(1);

f=1/dt;

X=fft(t);

F=X(1:

N/2+1);

f=f*(0:

N/2)/N;

plot(f,abs(F),'-*')

4.

P=[2,-3,0,5,13];

Q=[1,5,8];

p=polyder(P)

q=polyder(P,Q)

[a,b]=polyder(P,Q)

5.

P1=[1,2,4,0,5];

P2=[0,1,2];

P3=[1,2,3];

P=P1+conv(P2,P3)

X=roots(P)

A=[-1,1.2,-1.4;0.75,2,3.5;0,5,2.5];

p=polyval(P,A)

第6章

1.

(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

X=

1.2000

0.6000

0.6000

(2)

C=[0.95,0.67,0.53]';

X=A\C

X=

3.0000

-6.6000

6.6000

b3变大后,X1,X3明显增大,X2符号改变了,且绝对值仍然等于X3的绝对值。

(3)

cond(A)

ans=

1.3533e+003

2.

(1)(M文件)

functionfx=funx(x)

fx=x^41+x^3+1;

x=fzero('funx',-1)

x=

-0.9525

(2)(M文件)

functionfx=funx2(x)

fx=x-sin(x)/x;

x2=fzero('funx2',0.5)

x2=

0.8767

(3)functionq=fun3(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;

options=optimset('Display','off');

x=fsolve(@fun3,[1,1,1]',options)

x=

0.5991

2.3959

2.0050

q=fun3(x)

q=

1.0e-010*

0.22130.38040.0009

3.

(1)functionyp=fun4(t,y)

yp=-(1.2+sin(10*t))*y;

t0=0;

tf=5;

y0=1;

[t,y]=ode23(@fun4,[t0,tf],y0);

tf=5;

y0=1;

[t,y]=ode23(@fun4,[t0,tf],y0);

t'

ans=

Columns1through9

00.06670.13750.20030.26950.35280.43620.50330.5663

Columns10through18

0.63690.69130.74570.80810.87380.95911.02771.09631.1600

Columns19through27

1.22461.30821.37141.43471.50011.58421.65301.72191.7858

Columns28through36

1.85011.93191.99532.05872.12362.20532.27452.34382.4080

Columns37through45

2.47192.55012.61402.67792.74192.81932.90462.96853.0323

Columns46through54

3.09593.17213.23643.30073.36423.43953.53283.59653.6602

Columns55through63

3.72383.79983.86423.92863.99204.06714.14084.21444.2800

Columns64through72

4.34324.41594.48124.54654.60944.68124.75674.83224.8990

Columns73through74

4.96205.0000

y'

ans=

Columns1through9

1.00000.90350.78220.68230.59840.54020.51820.51060.4976

Columns10through18

0.46560.42800.38440.33550.29360.25950.24690.24210.2382

Columns19through27

0.22900.20540.18190.15850.13870.12250.11640.11400.1122

Columns28through36

0.10800.09740.08640.07530.06580.05810.05490.05370.0529

Columns37through45

0.05110.04660.04150.03610.03160.02780.02580.02530.0249

Columns46through54

0.02410.02210.01970.01720.01500.01320.01220.01190.0117

Columns55through63

0.01140.01040.00930.00810.00710.00620.00580.00560.0055

Columns64through72

0.00540.00500.00450.00390.00340.00300.00270.00260.0026

Columns73through74

0.00250.0025

(2)

functionyp=funb(t,y)

yp=cos(t)-y/(1+t^2);

t0=0;

tf=5;

y0=1;[t,y]=ode23('funb',[t0,tf],y0);

t'

ans=

Columns1through9

00.50000.80161.10331.40771.75372.23012.52152.8129

Columns10through18

2.97273.13263.30013.50913.75494.03754.36374.75845.0000

y'

ans=

Columns1through9

1.00001.01461.03631.04501.01620.91570.64510.41220.1437

Columns10through18

-0.0122-0.1699-0.3330-0.5273-0.7327-0.9233-1.0649-1.1040-1.0534

4.

functionfx=mymin(x)

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 工学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1