2D function with surf and surfc

7 ビュー (過去 30 日間)
Andre589
Andre589 2016 年 9 月 24 日
コメント済み: Star Strider 2016 年 9 月 24 日
Hello guys, I am kinda new to MatLab and I have a question for this exercise. I have to plot this function f(x,y)=cos(x)*sin(y). x,y Element of [-pi,pi] with 0.1 steps.
So I have to use surf and surfc for this and do a subplot. But I really have no clue how to start at this can someone help me I would be very grateful.
We got a hint for this exercise we should use the command meshgrid.

回答 (1 件)

Star Strider
Star Strider 2016 年 9 月 24 日
You need to characterise your function as a vectorised anonymous function:
f = @(x,y) cos(x).*sin(y);
define ‘x’ and ‘y’ using the colon ‘:’ operator, and the meshgrid function to produce the grids you will need to do the calculations and the plot.
Helpful parts of the documentation are Array vs. Matrix Operations, Function Basics, and colon.
  2 件のコメント
Andre589
Andre589 2016 年 9 月 24 日
So at the moment I have this
[X,Y] = meshgrid(-pi:.1:pi);
Z = cos(x).*sin(y);
surf(X,Y,Z)
But its not working right now. Can you tell me what did I wrong?
Star Strider
Star Strider 2016 年 9 月 24 日
Yes.
MATLAB is case-sensitive, so ‘x’ is not the same as ‘X’. You need to calculate ‘Z’ using ‘X’ and ‘Y’.
Everything else looks correct. With that change, you should get an interesting-looking plot.

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by