How do I plot this function in MATLAB?

조회 수: 31 (최근 30일)
Michael
Michael 2014년 10월 14일
답변: Shashyabh Ray 2021년 3월 2일
Hello Everyone,
I am having trouble with entering the equation Z = sin(sqrt(x.^2 + y.^2))/(sqrt(x.^2 + y.^2)) into MATLAB so I can plot it as a surface plot. The MATLAB program keeps on turning this equation into the value -0.0227, rather than accecpting it as an equation (which make no sense).
This issue is preventing me from making a surface plot, as I am told that Z is a scalar or vector (because the program computed it as that for some reason), rather than a matrix.
Can anyone tell me what I am doing wrong with either the syntax or another aspect of the entry?
I would greatly appreciate it.
Thank you
  댓글 수: 1
Stephen23
Stephen23 2014년 10월 14일
편집: Stephen23 2014년 10월 14일
Information on the differences between array and matrix operations:
That list of operations that these difference apply to is important to keep in mind!

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

채택된 답변

Michael
Michael 2014년 10월 14일
Nevermind, I solved this issue by adding a period (.) before the division (/) sign, so now things look like this:
Z = sin(sqrt(X.^2 + Y.^2))./(sqrt(X.^2 + Y.^2))

추가 답변 (2개)

Mischa Kim
Mischa Kim 2014년 10월 14일
편집: Mischa Kim 2014년 10월 14일
Michael, use something like
[x,y] = meshgrid(0:0.1:5,0:0.1:5);
Z = sin(sqrt(x.^2 + y.^2))./(sqrt(x.^2 + y.^2)) ;
surf(x,y,Z)
  댓글 수: 1
Michael
Michael 2014년 10월 14일
Thanks Mischa,
I've done something similar to that and everything looks wonderful.
- Mike

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


Shashyabh Ray
Shashyabh Ray 2021년 3월 2일
how to plot y=(exp.^(sqrt(x)))./(x*x - x*(exp(x))).^(1/3);

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by