####1. 绘制曲线
(1)
x=(-5:0.01:5);
y=(1/(2*pi))*exp(-(x.^2)/2);
subplot(1,2,1)
plot(x,y)
subplot(1,2,2)
fplot(@(x)(1/(2*pi))*exp(-(x.^2)/2),[-5,5],'r')
分别用了plot和fplot函数,结果如下:
(2)
t=-1:0.01:1;
x=t.^2;
y=5*t.^3;
subplot(1,2,1)
plot(x,y,'r')
subplot(1,2,2)
fplot(@(t)t.^2,@(t)5*t.^3,[-1,1],'g')
####2. 同坐标轴绘制
x=-3:0.01:3;
y=(x.^2)/2;
t=0:0.01:pi;
a=sin(3*t).*cos(t);
b=sin(3*t).*sin(t);
plot(x,y,'r--',a,b,'k-.')
另一种:
x1=linspace(-3,3,100);
y1=x1.^2/2;
t=linspace(0,pi,100);
x2=3*sin(3*t).*cos(t);
y2=3*sin(3*t).*sin(t);
plot(x1,y1,'r--',x2,y2,'k-.')
####3. 曲面绘制
三种绘制曲面的函数:
[u,v]=meshgrid(0:0.01:pi,0:0.01:pi);
x=(1+cos(u)).*cos(v);
y=(1+cos(u)).*sin(v);
z=sin(u);
subplot(1,3,1)
plot3(x,y,z)
subplot(1,3,2)
mesh(x,y,z)
subplot(1,3,3)
surf(x,y,z)
grid on