matlab答案

matlab答案
matlab答案

第五章

1.绘制下列曲线。

(1)2

1100

x

y += (2)22

21x e y -=π (3)12

2

=+y x (4)?

??==3

2

5t y t x 答:

(1) x=-10:0.1:10; y=100./(1+x.^2); plot(x,y)

(2) x=-10:0.1:10;

y=1/(2*pi)*exp(-x.^2/2); plot(x,y)

(3) ezplot('x^2+y^2=1')

(4)

t=-10:0.1:10; x=t.^2; y=5*t.^3;

plot(x,y)

2. 绘制下列三维图形。

(1)??

?

??===t z t y t x sin cos

(2)??

?

??=+=+=u z v u y v u x sin sin )cos 1(cos )cos 1(

(3)5=z

(4)半径为10的球面(提示:用sphere 函数

答: (1)

t=0:pi/100:2*pi; x=cos(t); y=sin(t); z=t;

plot3(x,y,z)

(2)

u=0:pi/100:2*pi;

v=0:pi/100:2*pi;

x=(1+cos(u)).*cos(v);

y=(1+cos(u)).*sin(v);

z=sin(u);

plot3(x,y,z)

(3)

[x,y]=meshgrid(-100:100); z=5*ones(size(x));

mesh(x,y,z)

(4)

[x,y,z] = sphere; %等价于sphere(20) 20是画出来的球面的经纬分面数...20的话就是20个经度, 20个纬度,或者说“就是划出20╳20面的单位球体,把球的表面分成400个小网格”

surf(x,y,z); %绘制单位球面 x = 10*x; y = 10*y; z = 10*z;

surf(x,y,z); %绘制半径为10的球面 axis equal

3.在同一图形窗口中采用子图形式分别绘制正方形、圆、三角形和六边形。 答:

n=[3 4 6 2^10] for i=1:4

subplot(2,2,i)

theta=linspace(pi/n(i),2*pi+pi/n(i),n(i)+1); plot(cos(theta),sin(theta)); axis equal; end

4. 分别用plot 和fplot 绘制下列分段函数的曲线。

?????<--+=>+++=0,510,00,51)(342x x x x x x x x f

答:

plot 函数: 方法一:

x=linspace(-10,10,200); y=[]; for x0=x if x0>0

y=[y,x0.^2+(1+x0).^(1/4)+5]; elseif x0==0 y=[y,0]; elseif x0<0

y=[y,x0.^3+sqrt(1-x0)-5]; end end

plot(x,y)

方法二:

x=linspace(-10,10,200);

y=(x<0).*(x.^3+sqrt(1-x)-5)+(x==0).*0+(x>0).*(x.^2+(1+x).^(1/4)+5);

plot(x,y)

用fplot函数:

fplot('(x<0).*(x.^3+sqrt(1-x)-5)+(x==0).*0+(x>0).*(x.^2+(1+x).^(1/4)+5)',[-10,10])

5. 在同一坐标轴中绘制下列两条曲线并标注两曲线的交叉点。 (1)5.02-=x y

(2)??

?

?

?=≤≤=t t y t t t x sin )3sin(0cos )3sin(π 答: 相邻两点x1、x2 曲线(1)相应的y 值为y11、y12, 曲线(2)y 相应的y 值y21、y22, 若(y11-y21)与(y12-y22)符号相反或等于0,则x1或x2就是一个交叉点。 方法一:

t=linspace(0,pi,300); x=sin(3*t).*cos(t); y1=2*x-0.5;

y2=sin(3*t).*sin(t); len=length(t); p=y1-y2;

x3=x((find(p(1:len-1).*p(2:len)<=0))); y3=2*x3-0.5;

plot(x,y1,x,y2,x3,y3,'rd')

方法二:用循环 %t=0:0.01:pi;

t=linspace(0,pi,100); x=sin(3*t).*cos(t); y1=2*x-0.5;

y2=sin(3*t).*sin(t); plot(x,y1,x,y2);grid; delta_y=y1-y2;

% figure;stem(delta_y); j=1;

for i=1:length(t)-1

if delta_y(i)*delta_y(i+1)<=0 position(j)=i+1; j=j+1; end end hold on;

plot(x(position),y1(position),'ro'); title('两条曲线相交'); xlabel('x');ylabel('y'); h = legend('y1','y2');

相关主题
相关文档
最新文档