Effacer les filtres
Effacer les filtres

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

5 vues (au cours des 30 derniers jours)
Nittya Ananda
Nittya Ananda le 19 Fév 2023
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);

Réponses (1)

Walter Roberson
Walter Roberson le 19 Fév 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.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by