今天,带来Matlab中,绘制三维表达式、三变量方程式、三变量函数、三维参数化曲线的图形绘制方法,即绘制 f(x,y,z) 的图形,主要包括三维参数化函数、参数范围指定、线条曲线标记、多线条绘制、线条曲线的修改、坐标轴刻度修改等常用绘图方法。
下面我们将开始非常详细的 Matlab fplot3 函数语法介绍,实例引用,结果展示。首先,我们给出 Matlab 中关于 fplot3 函数的帮助文本如下:
>> help fplot3 fplot3 Plot 3-D parametric curve fplot3(FUNX,FUNY,FUNZ) plots the parametric curve FUNX(T), FUNY(T), and FUNZ(T) over the default domain -5 < T < 5. fplot3(FUNX,FUNY,FUNZ,[TMIN TMAX]) plots the curve FUNX(T), FUNY(T), and FUNZ(T) over TMIN < T < TMAX. fplot3(...,'LineSpec') plots with the given line specification. fplot3(AX,...) plots into AX instead of the current axes. H = fplot3(...) returns handles to the plotted objects in H. Examples: fplot3(@sin,@cos,@log) fplot3(@(t) sin(2*t),@(t) cos(t), @(t) sin(3*t+2), [-pi,pi], '--*') fplot3(@cos, @(t) t.*sin(t), @sqrt) fplot3(@(x)x.*cos(x),@(x)x.*sin(x),@log,[0.1 123],'LineWidth',2) If your function has additional parameters, for example k in myfuntk: %-----------------------% function s = myfuntk(t,k) s = t.^k .* sin(t); %-----------------------% then you may use an anonymous function to specify that parameter: fplot3(@cos,@(t)myfuntk(t,1),@sqrt)
常见用法
fplot3(funx,funy,funz) fplot3(funx,funy,funz,tinterval) fplot3(___,LineSpec) fplot3(___,Name,Value) fplot3(ax,___) fp = fplot3(___)
语法说明
fplot3(funx,funy,funz) 在默认区间 [-5,5](对于 t)绘制由 x = funx(t)、y = funy(t) 和 z = funz(t) 定义的参数化曲线。
fplot3(funx,funy,funz,tinterval) 将在指定区间绘图。将区间指定为 [tmin tmax] 形式的二元素向量。
fplot3(___,LineSpec) 设置线型、标记符号和线条颜色。例如,’-r’ 指定红色线条。在前面的任何输入参数组合之后使用此选项。
fplot3(___,Name,Value) 使用一个或多个名称-值对组参数指定线条属性。例如,’LineWidth’,2 指定 2 磅的线宽。
fplot3(ax,___) 将图形绘制到 ax 指定的坐标区中,而不是当前坐标区中。指定坐标区作为第一个输入参数。
fp = fplot3(___) 返回 ParameterizedFunctionLine 对象。可使用此对象查询和修改特定线条的属性。
三维参数化线条绘制
绘制三维参数化线条
x=sin(t)
y=cos(t)
z=t
(在默认参数范围 [-5 5] 内。)
xt = @(t) sin(t); yt = @(t) cos(t); zt = @(t) t; fplot3(xt,yt,zt)
参数范围指定
绘制参数化线条
x=e−t/10sin(5t)
y=e−t/10cos(5t)
z=t
(通过指定 fplot3 的第四个输入实参,在形参范围 [-10 10] 内绘制)。
xt = @(t) exp(-t/10).*sin(5*t); yt = @(t) exp(-t/10).*cos(5*t); zt = @(t) t; fplot3(xt,yt,zt,[-10 10])
线条曲线标记
在参数的不同区间,将同一条三维参数化曲线绘制三次。对于第一个区间,使用 2 磅的线宽。对于第二个,指定带有圆形标记的红色虚线线型。对于第三个,指定带有星号标记的青蓝色点划线线型。
fplot3(@(t)sin(t), @(t)cos(t), @(t)t, [0 2*pi], 'LineWidth', 2) hold on fplot3(@(t)sin(t), @(t)cos(t), @(t)t, [2*pi 4*pi], '--or') fplot3(@(t)sin(t), @(t)cos(t), @(t)t, [4*pi 6*pi], '-.*c') hold off
多线条绘制
使用 hold on 在相同的坐标区中绘制多个线条。
fplot3(@(t)t, @(t)t, @(t)t) hold on fplot3(@(t)-t, @(t)t, @(t)-t) hold off
线条曲线的修改
绘制参数化线条
x=e−|t|/10sin(5|t|)
y=e−|t|/10cos(5|t|)
z=t.
将参数化函数行对象指定给变量。
xt = @(t)exp(-abs(t)/10).*sin(5*abs(t)); yt = @(t)exp(-abs(t)/10).*cos(5*abs(t)); zt = @(t)t; fp = fplot3(xt,yt,zt)
fp = ParameterizedFunctionLine with properties: XFunction: @(t)exp(-abs(t)/10).*sin(5*abs(t)) YFunction: @(t)exp(-abs(t)/10).*cos(5*abs(t)) ZFunction: @(t)t Color: [0 0.4470 0.7410] LineStyle: '-' LineWidth: 0.5000 Show all properties
将参数值范围更改为 [-10 10],并将线条颜色更改为红色。
fp.TRange = [-10 10]; fp.Color = 'r';
坐标轴刻度修改
为从 −2π 到 2π 范围内的 t 值绘制参数化线条
x=t
y=t/2
z=sin(6t).
添加标题、x 轴标签和 y 轴标签。此外,还可以更改坐标区视图并显示坐标区框轮廓。
xt = @(t)t; yt = @(t)t/2; zt = @(t)sin(6*t); fplot3(xt,yt,zt,[-2*pi 2*pi],'MeshDensity',30,'LineWidth',1); title('x=t, y=t/2, z=sin(6t) for -2\pi<t<2\pi') xlabel('x'); ylabel('y'); view(52.5,30) box on
使用 gca 访问坐标区对象。使用坐标区对象的 XTick 和 XTickLabel 属性指定 x 轴刻度值和关联的标签。按照同样的方式指定 y 轴刻度值和关联的标签。
ax = gca; ax.XTick = -2*pi:pi/2:2*pi; ax.XTickLabel = {'-2\pi','-3\pi/2','-\pi','-\pi/2','0','\pi/2','\pi','3\pi/2','2\pi'}; ax.YTick = -pi:pi/2:pi; ax.YTickLabel = {'-\pi','-\pi/2','0','\pi/2','\pi'};
暂无评论内容