当前位置:文档之家› 刘卫国版MATLAB程序设计与应用课后实验六八九

刘卫国版MATLAB程序设计与应用课后实验六八九

实验六 高层绘图操作

%第一题:

程序代码如下:

x=linspace(0,2*pi,101);

y=(0.5+3*sin(x)./(1+x.^2)).*cos(x);

plot(x,y)

01234567-1-0.500.511.5

%第二题:

%(1)

程序代码如下:

x=linspace(-2*pi,2*pi,100);

y1=x.^2;

y2=cos(2*x);

y3=y1.*y2;

plot(x,y1,'b-',x,y2,'r:',x,y3,'y--');

text(4,16,'\leftarrow y1=x^2');

text(6*pi/4,-1,'\downarrow y2=cos(2*x)');

text(-1.5*pi,-2.25*pi*pi,'\uparrow y3=y1*y2');

-8-6-4-202468-30-20-10010203040 y1=x2 y2=cos(2*x) y3=y1*y2

%(2)

程序代码如下:

x=linspace(-2*pi,2*pi,100);

y1=x.^2;

y2=cos(2*x);

y3=y1.*y2;

subplot(1,3,1);%分区

plot(x,y1);

title('y1=x^2');%设置标题

subplot(1,3,2);

plot(x,y2);

title('y2=cos(2*x)');

subplot(1,3,3);

plot(x,y3);

title('y3=x^2*cos(2*x)');

-100100510152025303540y1=x2-10010-1-0.8-0.6-0.4-0.200.20.40.60.81y2=cos(2*x)-10010-30-20-10010203040y3=x2*cos(2*x)

%(3)

程序代码如下:

x=linspace(-2*pi,2*pi,20);

y1=x.^2;

subplot(2,2,1);%分区

bar(x,y1);

title('y1=x^2的条形图');%设置标题

subplot(2,2,2);

stairs(x,y1);

title('y1=x^2的阶梯图');

subplot(2,2,3);

stem(x,y1);

title('y1=x^2的杆图');

subplot(2,2,4);

fill(x,y1,'r');%如果少了'r'则会出错

title('y1=x^2的填充图');

%其他的函数照样做。

-10-50510010203040y1=x2的条形图-10-50510010203040y1=x2的阶梯图-10-50510010203040y1=x2的杆图-10-50510010203040y1=x2的填充图

%第三题

程序代码如下:

x=-5:0.01:5;

y=[];%起始设y为空向量

for x0=x

if x0<=0 %不能写成x0=<0

y=[y,(x0+sqrt(pi))/exp(2)]; %将x对应的函数值放到y中

else

y=[y,0.5*log(x0+sqrt(1+x0^2))];

end

end

plot(x,y)

-10-50510010203040y1=x2的条形图-10-50510010203040y1=x2的阶梯图-10-50510010203040y1=x2的杆图-505-0.500.511.5

%第四题:

程序代码如下:

a=input('a=');

b=input('b=');

n=input('n=');

t=-2*pi:0.01:2*pi;

r=a*sin(b+n*t);

polar(t,r)

a=8

b=6

n=12 2 4 6 83021060240902701203001503301800

%第五题

程序代码如下:

x=linspace(-5,5,21);

y=linspace(0,10,31);

[x,y]=meshgrid(x,y);%在[-5,5]*[0,10]的范围内生成网格坐标

z=cos(x).*cos(y).*exp(-sqrt(x.^2+y.^2)/4);

subplot(2,1,1);

surf(x,y,z);

subplot(2,1,2);

contour3(x,y,z,50);%其中50为高度的等级数,越大越密

-5050510-101-5050510-101

%第六题

程序代码如下:

ezsurf('cos(s)*cos(t)','cos(s)*sin(t)','sin(s)',[0,0.5*pi,0,1.5*pi]); %利用ezsurf隐函数

shading interp

%进行插值着色处理

-1-0.500.51-1-0.500.5100.20.40.60.811.2xx = cos(s) cos(t), y = cos(s) sin(t), z = sin(s)yz

实验八 数据处理与多项式运算

%第一题

%(1)

程序代码如下:

A=rand(1,30000);

b=mean(A)

std(A,0,2)

%(2)

max(A)

min(A)

%(3)

n=0;

for i=1:30000

if A(i)>0.5

n=n+1;

end

end

p=n/30000

b =

0.5026

ans =

0.2899

ans =

1.0000

ans =

1.5584e-005

p =

0.5044

%第二题

%(1)

程序代码如下:

A=45+51*rand(100,5);

[Y,U]=max(A)

[a,b]=min(A)

Y =

95.9123 95.6103 95.8956 95.7209 95.8496

U =

87 63 80 53 94

a =

45.6179 45.1797 45.5863 45.0149 45.1109

b =

67 8 86 78 74

%(2)

程序代码如下:

m=mean(A)

s=std(A)

m =

69.5675 68.0574 67.0498 71.7785 71.6872

s =

14.0750 14.5617 15.0046 14.9842 14.8491

%(3)

sum(A,2)

[Y,U]=max(ans)

[a,b]=min(ans)

ans =

329.5253

355.2437

361.9882

382.9321

321.6361

335.0289

322.4588

378.5933

349.8230

331.9004

429.4166

384.8956

335.0518

314.4342

347.8612

362.8625

327.3319

414.6802 384.9432

335.0784

325.4819

359.5369

344.5517

322.0939

323.0906

376.0888

364.3966

310.7507

334.6912

340.1887

335.4254

331.0611

307.5110

369.8695

367.3127

375.6964

325.8224

358.1734

297.8471

288.9244

285.8521

353.1431

346.2313

352.4237

313.1714

307.7676

352.4772

377.6382

391.4384

335.1801

373.4749

418.3996

415.3718

303.9919

314.5437

355.4934

302.5830

359.3754

373.0907

370.2539

342.8401

352.8497

相关主题