在Matlab中绘制三维图形和水平曲线

时间:2015-11-06 23:29:36

标签: matlab function graph

我下面的代码如下,但是我无法测试,因为我现在没有Matlab,而且当我最终得到它时,我恐怕没有时间自己测试它。我试图在三个不同类型的函数的y轴和x轴(仅两个维度)上绘制水平曲线的三维图形和图形。如果有人能指出下面的代码是否有问题,我将不胜感激。

**************************************************************
**plotting functions -- level curves and 3d graph** 

x_val = linspace(0, 100, 200); 
y_val = linspace(0, 100, 200); 
[x, y] = meshgrid(x_val, y_val); 
z = ln(x).+y.;  
figure 
contour3(y, x, z)
contour(y, x, z)


********************************

z = (x.^1/2)+y.;  
figure 
contour3(y, x, z)
contour(y, x, z)

*********************************


z = (x.^1/3)+y.; 
figure 
contour3(y, x, z)
contour(y, x, z)

2 个答案:

答案 0 :(得分:2)

ln不是有效的matlab符号,除了上面提到的多余点和注释格式。以下在Matlab上运行。

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%plotting functions -- level curves and 3d graph%% 

x_val = linspace(0, 100, 200); 
y_val = linspace(0, 100, 200); 
[x, y] = meshgrid(x_val, y_val); 
z = log(x)+y;  
figure 
contour3(y, x, z)
figure 
contour(y, x, z)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

z = (x.^1/2)+y;  
figure 
contour3(y, x, z)
figure 
contour(y, x, z)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


z = (x^1/3)+y; 
figure 
contour3(y, x, z)
figure 
contour(y, x, z)

答案 1 :(得分:0)

对于初学者来说,MATLAB中的注释是“%”而不是“*”。

我认为你有一些错误,试图做元素操作。

你的三个z分配点太多了:

 z = log(x)+y;  
 z = (x.^1/2)+y; 
 z = (x.^1/3)+y; 

没有必要使用“。+”,因为MATLAB会自动按元素添加矩阵。