MATLAB绘图(三维)

三维绘图

三维曲线的基本函数

plot3函数
plot3(x1,y1,z1,’选项’)
程序示例:

t=0:pi/50:2*pi;
x=8*cos(t);
y=4*sqrt(2)*sin(t);
z=-4*sqrt(2)*sin(t);
plot3(x,y,z,'p');
title('3D');
text(0,0,0,'origin');
xlabel('x'),ylabel('y'),zlabel('z');
grid;

图示:
在这里插入图片描述

三维曲线

meshgrid函数
x=a:dx:b;
y=c:dy:d;
[x,y]=meshgrid(x,y);

绘制三维曲线函数

mesh(x,y,z,c)
surf(x,y,z,c)

程序示例:

x=0:0.1:2*pi;
[x,y]=meshgrid(x);
z=sin(y).*cos(x);
mesh(x,y,z);
xlabel('x'),ylabel('y'),zlabel('z');
title('mesh');
figure(2);
surf(x,y,z);
xlabel('x'),ylabel('y'),zlabel('z');
title('surf');

图示:
在这里插入图片描述
在这里插入图片描述

标准三维曲面

sphere函数
cylinder函数

[x,y,z]=sphere(n)
[x,y,z]=cylinder(R,n)
程序示例:

t=0:pi/20:2*pi;
[x,y,z]=cylinder(2+sin(t),30);
subplot(1,3,1);
surf(x,y,z);
[x,y,z]=sphere;
subplot(1,3,2);
surf(x,y,z);
axis equal
[x,y,z]=peaks(30);
subplot(1,3,3);
meshz(x,y,z);

图示:
在这里插入图片描述

其他三维图形
bar3、 bar3h、 pie3、 fill3、 scatter3、 stem3 、quiver3
用法与二维相同

隐函数绘图

ezplot函数

  1. 对于函数y=f(x)
    ezplot(f):在默认-2π<x<2π绘制y=f(x)的图形,其中f可以是函数表达式或者函数文件名
    ezplot(f,[a,b]):在a<x<b绘制y=f(x)
  2. 对于隐函数f(x,y)=0
    ezplot(f):在默认-2π<x<2π绘制f(x,y)=0的图形
    ezplot(f,[a,b]):在a<x<b绘制f(x,y)=0的图形
    ezplot(f,[xmin,xmax,ymin,ymax]):在xmin<x<xmax和ymin<y<ymax绘制f(x,y)=0的图形
  3. 对于参数方程x=x(t)和y=y(t)
    ezplot(x,y):在默认-2π<x<2π绘制x=x(t)和y=y(t)的图形
    ezplot(x,y,[tmin,tmax]):在tmin<t<tmax绘制x=x(t)和y=y(t)的图形

程序示例:

subplot(2,2,1);
ezplot('x^2+y^2-9');axis equal
subplot(2,2,2);
ezplot(@(x,y) x^3+y^3-5*x*y+1/5);
subplot(2,2,3);
ezplot('cos(tan(pi*x))',[0,1])
subplot(2,2,4);
ezplot('8*cos(t)','4*sqrt(2)*sin(t)',[0,2*pi])

图示:
在这里插入图片描述

隐函数三维绘图

ezcontour、 ezcontourf、 ezmesh 、ezmeshc、 ezplot3 、ezpolar、 ezsurf、 ezsurfc
调用方法基本相同以ezsurf(f)为例
ezsurf(f):绘制z=f(x,y),默认-2π<x<2π,-2π<y<2π
ezsurf(f,[xmin,xmax,ymin,ymax]):在指定的区间绘制曲面z=f(x,y)
ezsurf(x,y,z):在默认区间-2π<x<2π,-2π<y<2π上绘制方程x=x(s,t),y=y(s,t),z=z(s,t)的曲面
ezsurf(x,y,z,[smin,smax,tmin,tmax]):使用指定的区域绘制参数方程曲面
绘制下列曲面:

                    0≤s≤8,0≤t≤5π

程序示例:

ezsurf(‘exp(-s)*cos(t)’,'exp(-s)sin(t)’,‘t’,[0,8,0,5pi])

图示:
在这里插入图片描述

图形修饰处理

view函数
view(az,el)
程序示例:

subplot(2,2,1);
mesh(peaks);
view(-37.5,30);
subplot(2,2,2);
mesh(peaks);
view(0,90);
subplot(2,2,3);
mesh(peaks);
view(90,0);
subplot(2,2,4);
mesh(peaks);
view(-7,-10);

图示:
在这里插入图片描述

图形的裁剪

NaN常数
程序示例:

x=0:pi/10:4*pi;
y=sin(x);
i=find(abs(y)>0.5);
x(i)=NaN;
plot(x,y);

图示:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

~猫七寻

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值