简体   繁体   English

在Matlab中绘制3-D图形和水平曲线

[英]Plotting 3-d graphs and level curves in Matlab

I have the following code below, but I cannot test it since I do not have Matlab with me right now and I am afraid I might not have the time to test it by myself when I finally get it. 我在下面有以下代码,但是由于我现在还没有Matlab,所以我无法对其进行测试,恐怕我最终拿到它时可能没有时间自己进行测试。 I'm trying to plot both 3-d graphs and graphs of the level curves in the y and x axis (two dimensions only) of three different types of functions. 我正在尝试在三种不同类型的函数的y和x轴(仅二维)上绘制3-d图和水平曲线图。 I would appreciate if someone could point if there is something wrong with the code below. 如果有人可以指出下面的代码有什么问题,我将不胜感激。

**************************************************************
**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)

ln is not a valid matlab symbol, in addition to the excess of dots mentioned and comment formatting above. 除了上面提到的点和注释格式过多之外,ln不是有效的matlab符号。 The following runs on 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)

For starters, comments in MATLAB are "%" not "*". 首先,MATLAB中的注释是“%”而不是“ *”。

You have a few mistakes, trying to do element-wise operators, I think. 我认为您有一些错误,尝试执行元素明智的运算符。

Your three assignments of z have too many dots: 您对z的三个分配有太多的点:

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

It is not necessary to use ".+", because MATLAB automatically adds matrices elementwise. 不需要使用“。+”,因为MATLAB会自动按元素添加矩阵。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM