Borrar filtros
Borrar filtros

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

5 visualizaciones (últimos 30 días)
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);

Respuestas (1)

Walter Roberson
Walter Roberson el 19 de Feb. de 2023
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.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by