フィルターのクリア

How do I plot a 3D graph of function that I have taken as input from the user?

5 ビュー (過去 30 日間)
Nittya Ananda
Nittya Ananda 2023 年 2 月 19 日
回答済み: Walter Roberson 2023 年 2 月 19 日
I want to write a code, where when I enter a function will return me a 3D plot of that function. This is the code I've written.
clc;
close all;
syms x y
f = input("f(x,y)");
x1=-5:1:5;
y1=x1';
[X1,Y1]=meshgrid(x1,y1);
Z1=subs(subs(f,x,X1),y,Y1);
surf(X1,Y1,z1);
But, every time I run it, it shows me an error.
f(x,y) - x*y (FunctionI passed as input)
Error using surf
Data dimensions must agree.
Error in project_prac4 (line 9)
surf(X1,Y1,z1);

回答 (1 件)

Walter Roberson
Walter Roberson 2023 年 2 月 19 日
z1 = subs(f, {x, y}, {X1, Y1});
You can only get away with subs(subs()) with scalars or with vectors with different orientations. You need simultaneous substitution for arrays.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by