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.
조회 수: 2 (최근 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);
댓글 수: 0
답변 (2개)
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
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
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
JEYGANESH JAYA KUMARAN
2020년 6월 20일
Hi, by using the above code, how to find value at a specific point in the mesh?
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!