Z must be a matrix, not scalar or vector

6 ビュー (過去 30 日間)
Daniel Walker
Daniel Walker 2020 年 8 月 4 日
コメント済み: Daniel Walker 2020 年 8 月 4 日
I've seen a bunch of other people ask similar questions, my code is a bit different.
The following were my originial commands before I tried to code it:
>> t=linspace(0, 2*pi);
>> x=2*cos(t);
>> y=sin(t)+cos(t)-1;
>> z=sin(t);
>> surf(x,y,z)
Error using surf (line 71)
Z must be a matrix, not a scalar or vector.
I am trying to graph the equation of the curve of intersection of curve (x^2)/2 + 2z^2=2 and plane x-y+z-1=0
Thanks for any help I can get!

採用された回答

Cris LaPierre
Cris LaPierre 2020 年 8 月 4 日
z needs to be the same size as X and Y. Perhaps you mean to do something like this?
t=linspace(0, 2*pi);
T = meshgrid(t);
x=2*cos(T);
y=sin(T)+cos(T)-1;
z=sin(T)
surf(x,y,z)
  1 件のコメント
Daniel Walker
Daniel Walker 2020 年 8 月 4 日
Your response was very helpfuland resulted in me getting this far. The eqn for the intersection seems correct. I'm still figuring out how to include all three equations (the eqn for the ellipsoid cylinder, the plane and the curve intersection between them) in the same frame. x^2/2 +2z^2 = 2 can be simplified to x^2/4 +z^2 = 1. In this format 2cost can be substituted for x with sint replacing z with the objective to make the eqn into 4cos^2(t)/4 + sin^2(t)=1.

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2020 年 8 月 4 日
t=linspace(0, 2*pi);
That is a row vector.
x=2*cos(t);
Row Vector.
y=sin(t)+cos(t)-1;
Row vector.
z=sin(t);
Row vector that does not depend upon x or y.
surf(x,y,z)
x, y, z are all row vectors.
In some cases it is valid for x and y to be vectors for surf, provided that length(x) = size(z,2) and length(y) = size(z,1). However, with your z being a row vector, then size(z,1) = 1 so your y would have to be length 1 to match... and even that would not be permitted as it does not give enough input values to form a surface out of.
In the code you show the image of, you do
[X,Y] = meshgrid(x,y);
and after that X and Y would be 2D matrices. However, that code still creates z from the row vector t.
curve of intersection of curve (x^2)/2 + 2z^2=2 and plane x-y+z-1=0
It is not at all obvious that you are plotting the intersection in what you posted. It looks to me more as if you are trying to plot the first curve in parameteric form. You could use more comments.
  1 件のコメント
Daniel Walker
Daniel Walker 2020 年 8 月 4 日
Thanks for your response. x^2/2 +2z^2 = 2 can be simplified to x^2/4 +z^2 = 1. In this format 2cost can be substituted for x with sint replacing z with the objective to make the eqn into 4cos^2(t)/4 + sin^2(t)=1. The graph is a parabaloid cylinder along the y axis which I feel very confident about. Just graphing the cylinder results in below:
However, I'm still trying to figure out how to neatly highlight the intersection of the curve and the plane and how that relates to the function which defines the intersection.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by