Matlab复习.docx

上传人:b****5 文档编号:3565508 上传时间:2022-11-23 格式:DOCX 页数:26 大小:202.07KB
下载 相关 举报
Matlab复习.docx_第1页
第1页 / 共26页
Matlab复习.docx_第2页
第2页 / 共26页
Matlab复习.docx_第3页
第3页 / 共26页
Matlab复习.docx_第4页
第4页 / 共26页
Matlab复习.docx_第5页
第5页 / 共26页
点击查看更多>>
下载资源
资源描述

Matlab复习.docx

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

Matlab复习.docx

Matlab复习

Matlab复习

1.

digits

2.1

2

vpa

(2)

vpa(2.1)

vpa(2.1,41)

Digits=32

ans=

2.1000

ans=

2

ans=

2.

ans=

2.1000000000000000000000000000000

ans=

2.1000000000000000000000000000000000000000

2.

a=3/7+0.1

b=sym(3/7+0.1)

c=vpa(sym(3/7+0.1))

who

whosabc

a=

0.5286

b=

37/70

c=

.52857142857142857142857142857143

Yourvariablesare:

aansbc

NameSizeBytesClass

a1x18doublearray

b1x1134symobject

c1x1190symobject

Grandtotalis41elementsusing332bytes

3.

symsk

symsxpositive

f=2/(2*k+1)*((x-1)/(x+1))^(2*k+1);

y=symsum(f,k,0,inf);

y=simple(y);

y=simple(y);

y=simple(y);

y=simple(y);

y=simple(y)

y=

log(-(x+1+((x-1)^2)^(1/2))/(-x-1+((x-1)^2)^(1/2)))

y1=-(1+((x^2-2*x+1)/(x^2+2*x+1))^(1/2))/(-1+((x^2-2*x+1)/(x^2+2*x+1))^(1/2))

y1=simple(y1)

y1=

(-1-((x^2-2*x+1)/(x^2+2*x+1))^(1/2))/(-1+((x^2-2*x+1)/(x^2+2*x+1))^(1/2))

y1=

x

4.

symsxy

f=x^2+y^2;

yk=int(int(f,y,1,x^2),x,1,2);

yk=vpa(yk,8)

yk=

9.5809524

5.

symst

y=abs(sin(t))

yt=diff(y,t)

yt1=limit(yt,t,0,'left')

yt2=subs(yt,t,pi/2)

y=

abs(sin(t))

yt=

abs(1,sin(t))*cos(t)

yt1=

-1

yt2=

0

6.

symsxt

f=sin(t)/t;

y=int(f,t,0,x);

ezplot(y,[0,2*pi])

y1=subs(y,x,4.5)

y2=vpa(limit(y,x,4.5))

y1=

1.6541

y2=

1.6541404143792439835039224868515

7.

symstao

symstpositive

ht=exp(-3*t);

ut=cos(t);

ht_tao=subs(ht,t,tao);

ut_tao=subs(ut,t,t-tao);

f=ht_tao*ut_tao;

y=simple(int(f,tao,0,t))

y=

-3/10/exp(t)^3+3/10*cos(t)+1/10*sin(t)

symsw

symstpositive

ht=exp(-3*t);

ut=cos(t);

Hw=simple(fourier(ht,t,w))

Uw=simple(fourier(ut,t,w))

f=simple(ifourier(Hw*Uw,w,t))

Hw=

fourier(exp(-3*t),t,w)

Uw=

pi*(Dirac(w-1)+Dirac(w+1))

f=

pi*(ifourier(fourier(exp(-3*t),t,w)*Dirac(w-1),w,t)+ifourier(fourier(exp(-3*t),t,w)*Dirac(w+1),w,t))

 

8.

symstwtao

symsA

f=A*(1-abs(t)/tao)*(heaviside(t-tao))-heaviside(t+tao));

Fs=fourier(f,t,w);

Fs1=subs(Fs,[A,tao],[2,2]);

ezplot(Fs1);

?

?

?

formatcompact;symstwtao

symsA

f=A*(1-abs(t)/tao)*(heaviside(t-tao))-heaviside(t+tao));

Fs=fourier(f,t,w);

Fs1=subs(Fs,[A,tao],[2,2]);

ezplot(Fs1);

|

Error:

Missingoperator,comma,orsemicolon.

helpheaviside

heaviside.mnotfound.

9.

symsst

Fs=(s+3)/(s^3+3*(s^2)+6*s+4);

f=ilaplace(Fs,s,t)

Fs1=simple(laplace(f,t,s))

Fs2=simple(Fs)

Fs1==Fs2

f=

2/3*exp(-t)+1/3*exp(-t)*3^(1/2)*sin(3^(1/2)*t)-2/3*exp(-t)*cos(3^(1/2)*t)

Fs1=

(s+3)/(1+s)/(4+2*s+s^2)

Fs2=

(s+3)/(s^3+3*s^2+6*s+4)

ans=

0

10.

symskTlambda

symsz

f=k*exp(-lambda*k*T);

Fz=ztrans(f,k,z)

f1=simple(iztrans(Fz,z,k))

f==f1

Fz=

z*exp(-lambda*T)/(z-exp(-lambda*T))^2

f1=

exp(-lambda*T)^k*k

ans=

0

11.

symsxy

s=solve('x^2+y^2','x*y=0')

disp('[s.x,s.y]')

disp([s.x,s.y])

s=

x:

[2x1sym]

y:

[2x1sym]

[s.x,s.y]

[0,0]

[0,0]

12.

symsxy

y=dsolve('Dy*y/5+x/4=0','x')

y=

[1/2*(-5*x^2+4*C1)^(1/2)]

[-1/2*(-5*x^2+4*C1)^(1/2)]

y1=1/2*(-5*x^2+4)^(1/2);

y2=-1/2*(-5*x^2+4)^(1/2);

subplot(1,2,1)

ezplot(y1)

gridon

subplot(1,2,2)

ezplot(y2)

gridon

shg

13.

symsfgx

dsolve('Df=3*f+4*g','Dg=-4*f+3*g','f(0)=0','g(0)=1','x')

ans=

f:

[1x1sym]

g:

[1x1sym]

14.

A=linspace(0,2*pi,10)

A=

Columns1through6

00.69811.39632.09442.79253.4907

Columns7through10

4.18884.88695.58516.2832

15.

rand('state',0)

A=rand(3,5);

LR=A>0.5

si=find(LR)

[ci,cj]=find(LR)

LR=

10001

01011

11110

si=

1

3

5

6

9

11

12

13

14

ci=

1

3

2

3

3

2

3

1

2

cj=

1

1

2

2

3

4

4

5

5

16.

clear

formatlong

rand('state',1)

A=rand(3,3)

B=diag(diag(A))

C=A-B

A=

0.952782149656620.598158524172190.83681960067634

0.704062166775000.840743198113070.51870305972492

0.953877473592230.442818842235130.02220977857260

B=

0.9527821496566200

00.840743198113070

.022*********

C=

00.598158524172190.83681960067634

0.7040621667750000.51870305972492

0.953877473592230.442818842235130

17.

x=-3*pi:

pi/15:

3*pi;

y=x;

[X,Y]=meshgrid(x,y);

warningoff

Z=sin(X).*sin(Y)./X./Y;

LR=isnan(Z);

s=sum(sum(LR))

xx=x+(x==0).*eps;

yy=y+(y==0).*eps;

[XX,YY]=meshgrid(xx,yy);

ZZ=sin(XX).*sin(YY)./XX./YY;

shadinginterp

zoomon

subplot(1,2,1)

surf(X,Y,Z)

subplot(1,2,2)

surf(XX,YY,ZZ)

shg

s=

181

18.

t=0:

0.02:

10;

t=t+(t==0).*eps;

y=sin(t)./t;

s=cumtrapz(t,y);

plot(t,s,'r')

19.

fx='exp(-abs(x)).*abs(sin(x))';

s=quad(fx,-5*pi,1.7*pi,1e-9)

s=

.0878********

symsx

fx='exp(-abs(x))*abs(sin(x))';

s=vpa(int(fx,x,-5*pi,1.7*pi))

s=

.0878********

formatlong

d=0.001;

t=-5*pi:

d:

1.7*pi;

fx='exp(-abs(x)).*abs(sin(x))';

s=d.*trapz(fx)

s=

1.90900000000000

20.

symst

y=dsolve('D2y-3*Dy+2*y=1','y(0)=1','Dy(0)=0','t');

y1=subs(y,t,0.5)

y1=

0.7896

DyDt.m

functionydot=DyDt(t,y)

ydot=[y

(2);3*y

(2)-2*y

(1)+1];

tspan=[0,30];

y0=[1,0];

[tt,yy]=ode45(@DyDt,tspan,y0);

subplot(1,2,1)

plot(tt,yy(:

1))

xlabel('t'),ylabel('x(t)')

subplot(1,2,2)

plot(yy(:

1),yy(:

2))

xlabel('s'),ylabel('v')

21.

A=magic(3);

b=ones(3,1);

r1=rank(A);

r2=rank(A,b);

ifr1==r2

ifr1==3

x1=A\b

else

x0=A\b;

xs=null(A);

x2=x0+xs*rand

(1)

end

else

error('Theresultisnotexist!

')

end

x1=

0.0667

0.0667

0.0667

A=magic(4);

ones(4,1)

r1=rank(A);

r2=rank(A,b);

ifr1==r2

ifr1==4

x1=A\b

else

x0=A\b;

xs=null(A);

x2=x0+xs*rand

(1)

end

else

error('Theresultisnotexist!

')

end

ans=

1

1

1

1

Warning:

Matrixisclosetosingularorbadlyscaled.

Resultsmaybeinaccurate.RCOND=1.306145e-017.

(Type"warningoffMATLAB:

nearlySingularMatrix"tosuppressthiswarning.)

x2=

1.0e+015*

-0.5629

-1.6888

1.6888

0.5629

A=magic(4);

b=[1;2;3;4];

r1=rank(A);

r2=rank(A,b);

ifr1==r2

ifr1==4

x1=A\b

else

x0=A\b;

xs=null(A);

x2=x0+xs*rand

(1)

end

else

error('Theresultisnotexist!

')

end

Warning:

Matrixisclosetosingularorbadlyscaled.

Resultsmaybeinaccurate.RCOND=1.306145e-017.

(Type"warningoffMATLAB:

nearlySingularMatrix"tosuppressthiswarning.)

x2=

1.0e+015*

-0.5629

-1.6888

1.6888

0.5629

22.

symsxy

s=solve('sin(x-y)=0','cos(x+y)=0','x','y')

disp('s.x'),disp('x.y')

disp(s.x),disp(x.y)

s=

x:

[2x1sym]

y:

[2x1sym]

s.x

x.y

[1/4*pi]

[-1/4*pi]

?

?

?

Accesstoanobject'sfieldsisonlypermittedwithinitsmethods.

23.

p1=conv([3,0,1,0],[1,0,0,0.5]);

p2=conv([1,2,-2],[5,2,0,1]);

[q,r]=deconv(p1,p2)

conv(p2,q)+r==p1

q=

0.6000-1.4400

r=

Columns1through6

-0.00000.000021.8800-5.3400-5.52004.5800

Column7

-2.8800

ans=

1111111

24.

h=[0.05,0.24,0.40,0.24,0.15,-0.1,0.1];

rand('state',1)

u=2*(randn(1,100)>0.5)-1;

t1=0;

t2=105;

tt=t1:

t2;

t=0:

99;

y=conv(u,h);

subplot(2,1,1)

stem(t,u)

subplot(2,1,2)

stem(y)

25.

clf

a=4;

b=2;

t=linspace(0,2*pi,150);

x=a.*cos(t);

y=b.*sin(t);

plot(x,y,'.r','Markersize',18)

axis([-4,4,-3,3])

xlabel('x'),ylabel('y')

26.

t=linspace(0,2*pi,100);

rho=1-cos(t);

polar(t,rho);

title('\fontsize{15}{\rho}=1-cos{\theta}')

axisequal

27.

A=[170,120,180,200,190,220];

B=[120,100,110,180,170,180];

C=[70,50,80,100,95,120];

D=[A;B;C]'

subplot(2,1,1)

colormap(hot)

bar(D,'stacked')

subplot(2,1,2)

bar(D,'grouped')

D=

17012070

12010050

18011080

200180100

19017095

220180120

28.

clf

t=linspace(0,8*pi,400);

x=sin(t);

y=cos(t);

z=t;

plot3(x,y,z,'y-','linewidth',10)

 

29.

mesh(peaks)

hiddenoff

x=-3:

0.2:

3;

y=x;

[x1,y1]=meshgrid(x,y);

z1=4*x1.*exp(-x1.^2-y1.^2);

colormap(hot)

mesh(x1,y1,z1)

hiddenoff

 

30.

clf

x=-4*pi:

pi/50:

4*pi;

y=x;

[x1,y1]=meshgrid(x,y);

k=x1+y1+((x1+y1)==0)*eps;

z1=sin(k)./k;

surf(x1,y1,z1)

shadinginterp

colormap(summer)

materialshiny

view(30,30)

title('\fontsize{15}z=sin(x+y)/(x+y)')

31.水仙花数

form=100:

999;

m1=fix(m/100);

m2=rem(fix(m/10),10);

m3=rem(m,10);

ifm==m1*m1*m1+m2*m2*m2+m3*m3*m3

disp(m)

end

end

153

370

371

407

form=100:

999;

m1=fix(m./100);

m2=fix(m./10)-m1.*10;

m3=m-m1.*100-m2.*10;

ifm==m1.*m1.*m1+m2.*m2.*m2+m3.*m3.*m3

disp(m)

end

end

153

370

371

407

32.完数

form=1:

500;

s=0;

fork=1:

m/2;

ifrem(m,k)==0

s=s+k;

end

end

ifm==s

disp(m)

end

end

6

28

496

33.Fibonacci

a

(1)=1;

a

(2)=1;

i=2;

whilea(i)<=10000

a(i+1)=a(i)+a(i-1);

i=i+1;

end

i,a(i)

i=

21

ans=

10946

34.

form=100:

200;

ifrem(m,21)~=0

continue

end

break

end

m

m=

105

form=100:

200;

ifrem(m,21)~=0

continue

else

break

end

end

m

m=

105

35.注意:

在m编辑器中执行以下语句:

sum=0;

cnt=0;

val=input('Enteranum(Enter0toend!

):

');

while(val~=0)

sum=sum+val;

cnt=cnt+1;

val=input('Enteranum(Enter0toend!

):

');

end

if(cnt>0)

sum

mean=sum/cnt

end

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

当前位置:首页 > 教学研究 > 教学案例设计

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

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