Borrar filtros
Borrar filtros

Function to create surfaces directly

1 visualización (últimos 30 días)
Weronika Ring
Weronika Ring el 17 de En. de 2018
Editada: Stephen23 el 17 de En. de 2018
I'm trying to figure out a way of creating surfaces directly with a function. I have the code:
function V=sketch(f,x1,x2,y1,y2,n)
x=linspace(x1,x2,n); y=linspace(y1,y2,n);
[X,Y]=meshgrid(x,y);
Z=f(X,Y);
surf(X,Y,Z)
grid on, box on, hold on
end
but I keep getting the error that x is undefined, which is not true as I've defined it in the very beginning.
I'm using
sketch((@(x,y)exp(1+0.5.*cos(4*x).*(y-2))),-1,3,0,4,-30)
to sample the graph.
What am I doing wrong?
  1 comentario
Stephen23
Stephen23 el 17 de En. de 2018
Editada: Stephen23 el 17 de En. de 2018
Your function worked for me, without any error. And once I changed the number of points to a positive value it even plotted something:
sketch((@(x,y)exp(1+0.5.*cos(4*x).*(y-2))),-1,3,0,4,30) % note +30.
giving:

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by