This code crashes my MATLAB and I don't know y figure(2); x = linspace(0,2); y = linspace(5,7); [X,Y]=meshgrid(x,y); Z = sin(X*Y).*Y + Y*exp(-cos(X*Y^2)).*X; mesh(X,Y,Z); xlabel('x'); ylabel('y'); zlabel('z'); grid on; title('Question 4 plot');

1 visualización (últimos 30 días)
Hi, My MATLAB crashes when I try to execute this code,
MATLAB (R2015b) has stopped working
A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available.
[close program]
I am not sure where I went wrong.
Original Question was
Use the meshgrid() and mesh() functions to plot the function z = sin(xy)+y exp(− cos(x^2*y)) over x ∈ [0, 2], y ∈ [5, 7]. Note you should turn the grid on, label the axes, and give the plot a title.
clear;
figure(2);
x = linspace(0,2);
y = linspace(5,7);
[X,Y]=meshgrid(x,y);
Z = sin(X*Y).*Y + Y*exp(-cos(X*Y^2)).*X;
mesh(X,Y,Z);
xlabel('x');
ylabel('y');
zlabel('z');
grid on;
title('Question 4 plot');
  2 comentarios
Star Strider
Star Strider el 28 de Abr. de 2016
I know this doesn’t help, but with this assignment:
Z = sin(X.*Y).*Y + Y.*exp(-cos(X.*Y.^2)).*X;
your code ran for me without error.
------------------------------------------------------------------------------------------------
The first thing I would do is to put some fprintf statements in at various places, for example after the meshgrid call:
fprintf(1, '\n\tCall to ‘meshgrid’ successful\n')
and other places as appropriate. That can help if you don’t know where the crash is occurring. Then use the debugger functions to see what the problem is.
Scott
Scott el 28 de Abr. de 2016
Thanks, I double checked my correction and I had made a mistake.

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 28 de Abr. de 2016
Editada: Jan el 28 de Abr. de 2016
Z = sin(X*Y).*Y + Y*exp(-cos(X*Y^2)).*X;
I guess you want:
Z = sin(X .* Y) .* Y + Y .* exp(-cos(X .* Y^2)) .* X;
Note: Whenever you mention a "crash", post the complete error message.

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by