【发布时间】:2010-04-27 15:23:53
【问题描述】:
我希望在 MATLAB 中绘制隐式函数。像 x^3 + xy + y^2 = 36 ,方程不能做成简单的参数形式。有什么简单的方法吗?
【问题讨论】:
我希望在 MATLAB 中绘制隐式函数。像 x^3 + xy + y^2 = 36 ,方程不能做成简单的参数形式。有什么简单的方法吗?
【问题讨论】:
这里有几个选项...
ezplot(或在较新版本中推荐使用fplot):最简单的解决方案是使用函数ezplot:
ezplot('x.^3 + x.*y + y.^2 - 36', [-10 10 -10 10]);
这会给你以下情节:
contour:另一种选择是生成一组点,您将在其中评估函数 f(x,y) = x^3 + x*y + y^2,然后使用函数 contour 绘制等高线,其中 f(x,y) 等于 36:
[x, y] = meshgrid(-10:0.1:10); % Create a mesh of x and y points
f = x.^3+x.*y+y.^2; % Evaluate f at those points
contour(x, y, f, [36 36], 'b'); % Generate the contour plot
xlabel('x'); % Add an x label
ylabel('y'); % Add a y label
title('x^3 + x y + y^2 = 36'); % Add a title
以上将为您提供与ezplot 生成的图几乎相同的图:
【讨论】:
如果您想绘制隐式曲面,例如有角立方体,您可以执行以下操作。
这个想法是计算函数的所有值(即使它们不等于零),然后创建一个 isosurface 来定义你的相等性。在这个例子中,隐函数等于零。
fun=@(x,y,z)(1-x.^8-3.*y.^8-2.*z.^8+5.*x.^4.*z.^2.*y.^2+3.*y.^4.*x.^2.*z.^2) ;
[X,Y,Z]=meshgrid(-2:0.1:2,-2:0.1:2,-2:0.1:2);
val=fun(X,Y,Z);
fv=isosurface(X,Y,Z,val,0);
p = patch(fv);
isonormals(X,Y,Z,val,p)
set(p,'FaceColor' , 'red');
set(p,'EdgeColor' , 'none');
daspect([1,1,1])
view(3); axis tight
camlight
lighting phong
axis off
此外,正如@knedlsepp 所建议的,还有一个名为ezimplot3D 的Matlab 文件交换提交似乎也可以完成这项工作。
【讨论】:
R2016b 中有两个新函数可以绘制隐式函数:
fimplicit for f(x,y) = 0
fimplicit3 for f(x,y,z) = 0
【讨论】: