I am writing a code to convert 3D plot in to 2D plot for the given function. The code is as below
f=input('Enter any function in x and y f(x,y)=');
[x,y]=meshgrid (-10:0.5:10,-10:0.5:10);
figure
surf(x,y,f(x,y))
xlim([-11,11])
ylim([-11,11])
figure
surf(x,y,f(x,y))
view(90,0), shading interp
xlabel X, ylabel Y, zlabel Z
The code is sucessfully displays the results for @(x,y) sin(x.^2 + y.^2) & @(x,y) cos(x.^2 )*( y.^2), But for input like @(x,y)e^(-x.^2-y.^2)*(x.^2+y.^2) (I wish to check plots for exp(-x^2 -y^2) (x^2 +y^2)), it shows the error like "Undefined function or variable 'e'"
Please help me to sort out the error.

댓글 수: 2

Stephen23
Stephen23 2023년 2월 9일
"Please help me to sort out the error."
Either define e or use the EXP() function:
PSSHDA
PSSHDA 2023년 2월 9일
Thanks @Stephen23 I have added function like this..
function e =exp(x,y)
f=input('Enter any function in x and y f(x,y)=');
[x,y]=meshgrid (-10:0.5:10,-10:0.5:10);
figure
surf(x,y,f(x,y))
xlim([-11,11])
ylim([-11,11])
figure
surf(x,y,f(x,y))
view(90,0), shading interp
xlabel X, ylabel Y, zlabel Z
still the result is same. though the plot windows is opened but no plot is there...Am I doing right?

댓글을 달려면 로그인하십시오.

 채택된 답변

Torsten
Torsten 2023년 2월 9일

0 개 추천

@(x,y)exp(-(x.^2 +y.^2)).* (x.^2 +y.^2)
instead of
@(x,y)e^(-x.^2-y.^2)*(x.^2+y.^2)

댓글 수: 1

PSSHDA
PSSHDA 2023년 2월 9일
Thanks Torsten this works for me... Thank You very much

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Line Plots에 대해 자세히 알아보기

질문:

2023년 2월 9일

댓글:

2023년 2월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by