Azzera filtri
Azzera filtri

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

5 visualizzazioni (ultimi 30 giorni)
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);

Risposte (1)

Walter Roberson
Walter Roberson il 19 Feb 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.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by