필터 지우기
필터 지우기

HELP needed! (Error using surf, Z must be a matrix, not a scalar or vector)

조회 수: 2 (최근 30일)
Tonny
Tonny 2013년 10월 4일
답변: Walter Roberson 2013년 10월 7일
Hi guys,
I'm quite new to matlab and I'm required to plot this paraboloid graph. I have spend hours trying to solve but no result. Don't think it's a matter of cap's as well.
A= 1./1500;
X_r2 = 1;
Z_r2 = 0;
x = -10:.1:10;
y = -10:.1:10;
[X,Y] = meshgrid(x,y);
syms A X Y Z X_r2 Z_r2
Temp_Z = solve(sqrt((X-X_r2).^2 + Y.^2 + (Z-Z_r2).^2) - sqrt(X.^2 + Y.^2 + Z.^2) - A == 0 , Z );
Z = Temp_Z;
surf(X,Y,Z)
Please help!
  댓글 수: 4
Thomas
Thomas 2013년 10월 4일
You are overwriting your meshgrid matrices with symbolic vars
syms A X Y Z X_r2 Z_r2
...?
Tonny
Tonny 2013년 10월 5일
Hi Thomas and all,
I think my whole method of trying to plot a surface graph of a symbolic eqn is flawed.
Does anyone know how I can plot this the eqn above? It's suppose to be a paraboloid. I've tried ezsurf as well but having other errors there.
Thanks in advance. Tonny

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

답변 (3개)

cr
cr 2013년 10월 5일
Whoa, I think thats not quite what you want to do. What is the eqn you want to plot? If i'm plotting the eqn z = sin(sqrt(x^2+y^2))/sqrt(x^2+y^2), this is what I do:
a = -10:.1:10;
b=a;
[x,y] = meshgrid(a,b);
z = sin(sqrt(x.^2+y.^2))./sqrt(x.^2+y.^2);
surf(x,y,z)
  댓글 수: 1
Tonny
Tonny 2013년 10월 5일
Hi. What I needed to do is to solve the eqn above for z, then plot the graph of z.
What I was thinking of doing is to use the solve(eqn) function of Matlab to solve the eqn for z for me. Then use it to get a surface plot.
Apparently, using the solve(eqn) function will require me to use symbolic variables. So when I tried to use surf(x,y,z), an error "z must be a matrix, not a scalar or vector".

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


cr
cr 2013년 10월 7일
ok, that clarifies that you need to use solve. if solve function is giving you a closed form solution for your eqn, use subs to substitute for various values of x & y inside two loops. Or better, manipulate the result you get to vectorize it so that you can use meshgrid matrices. Then comes surf.

Walter Roberson
Walter Roberson 2013년 10월 7일
After you solve(), use matlabFunction() to convert the symbolic form to an anonymous function. You can then apply that to the meshgrid matrices.
There are going to be at least two solutions for each point. You need to select one of them or separate out the two parts before doing the matlabFunction()

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by