# 西农MATLAB实验3

MATLAB实验报告
? 实验名称

2．误差限图绘制函数 x=-2:0.2:2; y=sin(x); L=rand(1,length(x))/10; U=rand(1,length(x))/10; errorbar(x,y,L,U,':')

3.复数图绘制函数 z=[2+3i,2+2i,1-2i,4i,-3]; x=[2,2,1,0,-3]; y=[3,2,-2,4,0]; subplot(1,2,1),compass(z,'r') subplot(1,2,2),feather(x,y,'b')

4.条形图与直方图绘制函数 x=-pi:0.15:pi; y=sin(x); subplot(2,1,1), H=bar(x,y); xx=get(H,'xdata'); yy=get(H,'ydata'); subplot(2,1,2)

plot(xx,yy);

1. t=0:pi/50:2*pi;
y1=1.0013*t.^2; subplot(221) polar(t,y1); y2=cos(3.5*t); subplot(222) polar(t,y2); y3=sin(t)./t; subplot(223) polar(t,y3); y4=1-cos(7*t).^3; subplot(224) polar(t,y4)

120 150 180 210 240

90 40 60 20 30 0 330 270 300

120 150 180 210 240

90 1

60 0.5 30 0 330

270

300

120 150 180 210 240

90 1

60 0.5 30 0 330

120 150 180 210 240

90 2 1

60 30 0 330

270

300

270

300

2.

1. x=0:pi/50:2*pi;
y1=log2(x),y2=exp(x); plot(x,y1,x,y2); axis([0 10 -10 10]),grid on title('对数函数和指数函数') gtext('y1=log_2x'); gtext('y2=e^2'); xlabel('x'),ylabel('y')

2.

3. x=0:pi/50:10;
y=exp(x+5)+x.^3; semilogx(x,y); axis([1 10])

3.5

x 10

6

3

2.5

2

1.5

1

0.5

0 -2 10

10

-1

10

0

10

1

4. figure(1)
subplot(221) [x,y]=meshgrid(-3:0.124:3); z=peaks(x,y); mesh(x,y,z);

title('多峰函数') subplot(222) x=-0.5*pi+1:pi/50:0.5*pi+1; y=tan(x); plot(x,y),grid on;axis([0 pi -10 10]); title('正切函数') subplot(223) x=-pi:pi/50:pi; y=sin(x); plot(x,y); title('正弦函数') subplot(224) x=-0.5*pi:pi/50:3/2*pi; y=cos(x); plot(x,y); title('余弦函数')

-2

0

2

4

0

2

4

6

5. x=-10:0.012:20;
y1=2*x+5; y2=x.^2-3*x+1 figure(1) subplot(211) plot(x,y1),grid on;axis([-10 20 0 100]) title('y1=2x+5') subplot(212) plot(x,y2),grid on;axis([-10 20 0 100]) title('y2=x^2-3x+1')

y1=2x+5 100

50

0 -10

-5

0

5 y2=x 2-3x+1

10

15

20

100

50

0 -10

-5

0

5

10

15

20

6.
autumn 2 1.8 1.6 1.4 1.2 1 0.8 0.6 0.4 0.2 0

1

2

bone 2 1.8 1.6 1.4 1.2 1 0.8 0.6 0.4 0.2 0

1

2

cool 2 1.8 1.6 1.4 1.2 1 0.8 0.6 0.4 0.2 0

1

2

hot 2 1.8 1.6 1.4 1.2 1 0.8 0.6 0.4 0.2 0

1

2

hsv 2 1.8 1.6 1.4 1.2 1 0.8 0.6 0.4 0.2 0

1

2

gray 2 1.8 1.6 1.4 1.2 1 0.8 0.6 0.4 0.2 0

1

2

flag 2 1.8 1.6 1.4 1.2 1 0.8 0.6 0.4 0.2 0

1

2

line 2 1.8 1.6 1.4 1.2 1 0.8 0.6 0.4 0.2 0

1

2

7.

8.

50

0 3

5 2 1 0 0 -1 -2 网格曲线 -3 -5

60 40 20 0 5

0

-5

-3

-2

-1

0

1

2

3

9.

10

0 4

2

0

-2

-4

-4

-2

0

2

4

-3

10.

2

1