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

5 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by