필터 지우기
필터 지우기

How do I get a surface graph of my function f(x,y)?

조회 수: 2 (최근 30일)
DIMITRIS GEORGIADIS
DIMITRIS GEORGIADIS 2017년 11월 18일
댓글: Karan Gill 2017년 11월 20일
I have the following code. My function is f(x,y) = sin(x)+cos(y). I want to replace x, y with sets a and b, respectively. I ude the subs function, but Z is a 51x51 sym, instead of 51x51 double in order to be plotted. Where is my mistake?
syms x y
f = sin(x)+cos(y);
a = [0:0.1:5];
b = [1:0.1:6];
[X, Y] = meshgrid(a,b);
Z = subs(f,[x y], {X, Y});
surf(X,Y,Z)

채택된 답변

Star Strider
Star Strider 2017년 11월 18일
Use an anonymous function, and don’t use the Symbolic Math Toolbox. You don’t need it for this problem.
f = @(x,y) sin(x)+cos(y);
a = [0:0.1:5];
b = [1:0.1:6];
[X, Y] = meshgrid(a,b);
Z = f(X,Y);
surf(X,Y,Z)
  댓글 수: 5
Star Strider
Star Strider 2017년 11월 20일
As always, my pleasure!
Karan Gill
Karan Gill 2017년 11월 20일
@Dimitris, or use fsurf instead of fmesh.
@Star Strider, actually it's only
>> f = @(x,y) sin(x)+cos(y);
>> fsurf(f)

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by