I wrote the code to plot two dimension graph but it is not showing the correct graph.So can you check and tell me where the mistake is in the code.

5 次查看(过去 30 天)
ploting two dimensional graph for u(x,t)=x*exp(-t)+exp(-x)
x=linspace(0,1,6);
y=linspace(0,1,6);
[X Y]=meshgrid(x,y);
z=x*exp(-y)+exp(-x);
mesh(x,y,z);

回答(2 个)

Star Strider
Star Strider 2017-6-4
I created an anonymous function for ‘z’, that illustrates what you need to do to plot your function.
This works:
x=linspace(0,1,6);
y=linspace(0,1,6);
[X Y]=meshgrid(x,y);
z = @(x,y) x.*exp(-y)+exp(-x);
mesh(x,y,z(X,Y))
You need to use the meshgrid-created ‘X’ and ‘Y’ matrices to calculate ‘z’. You also need to use element-wise multiplication. See the documentation on Array vs. Matrix Operations for element-wise operations, and on Anonymous Functions for them.
You may also need to use the ‘X’ and ‘Y’ matrices in your mesh call. In recent MATLAB releases you can use the vectors. The alternative is:
mesh(X,Y,z(X,Y))
  2 个评论
YOGESHWARI PATEL
YOGESHWARI PATEL 2017-6-4
编辑:Star Strider 2017-6-4
x = linspace(-10,10 ,51)';
y = linspace(0,0.3,51)';
[X, Y] = meshgrid(x, y);
Z=X/(1+Y);
surf(X, Y, Z);
ylabel('t');
xlabel('x');
zlabel('u(x,t)')
Now its showing error Warning: Matrix is singular to working precision. and graph is not display.
Star Strider
Star Strider 2017-6-4
You need to use element-wise operations, as I mentioned in my original Answer.
Try this:
Z=X./(1+Y);
Note the ‘./’ denoting element-wise division, instead of ‘/’ denoting matrix right-division.

请先登录,再进行评论。


Walter Roberson
Walter Roberson 2017-6-4
x = linspace(0, 1, 6);
y = linspace(0, 1, 6);
[X, Y] = meshgrid(x, y);
Z = X .* exp(-Y) + exp(-X);
mesh(X, Y, Z);
  3 个评论

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Directed Graphs 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by