Using the surf and meshgrid command

i am trying to plot a function using the surf and meshgrid commands
use the meshgrid and surf commands to plot y = sin(x cos(z)))
this is the code i have so far im not sure how to continue using the surf command and what is wrong with my current code
x = linspace(-1,1);
y = linspace(-1,1);
[x,y] = meshgrid(x,y);
y = sin*(x cos(z))
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.

 採用された回答

Star Strider
Star Strider 2023 年 3 月 25 日

0 投票

I am not certain what function you want to plot, since you did not create ‘z’ as a separate matrix. (I am creating it here in place of matrix ‘y’.
Since this is a bit ambiguous, two options —
x = linspace(-1,1, 50);
z = linspace(-1,1, 50);
[x,z] = meshgrid(x,z);
y = sin(x.*cos(z));
figure
surf(x, y, z)
colormap(turbo)
figure
surf(x, z, y)
colormap(turbo)
.

3 件のコメント

lateef
lateef 2023 年 3 月 26 日
y = sin(x cos(z)) is the only function i want to plot per my instructor im supposed to use the meshgrid and surf commands
Matt J
Matt J 2023 年 3 月 26 日
@lateef Well, you've had quite a few homework hints, so perhaps you should carry the ball from here...
Star Strider
Star Strider 2023 年 3 月 26 日
@lateef — This should work, then.
I am just not certain what is to be plotted, or how it is to be plotted, since ‘z’ is not specifically defined anywhere.

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

その他の回答 (1 件)

Catalytic
Catalytic 2023 年 3 月 25 日

0 投票

Use fimplicit3 instead
fimplicit3(@(x,y,z) y - sin(x.* cos(z)) ,[-1,1] )

1 件のコメント

lateef
lateef 2023 年 3 月 26 日
per my instructor i am supoosed to use the surf and meshgrid commands

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

カテゴリ

タグ

質問済み:

2023 年 3 月 25 日

コメント済み:

2023 年 3 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by