MATLAB [matlab] something wrong with my code

  • Thread starter Thread starter Ann_Hope
  • Start date Start date
  • Tags Tags
    Code Matlab
AI Thread Summary
To create a 3D surface plot in MATLAB using the equation z = cos(x+y)*cos(3x-y)+cos(x-y)*sin(x+3y)+5e^(x^2+y^2)/8, it's essential to first define the variables X and Y properly. The recommended approach involves using the meshgrid function to create a grid of X and Y values, such as X, Y = meshgrid(-8:.5:8). This grid is necessary for calculating the corresponding Z values. The Z calculation should also ensure proper syntax, particularly using the exp function correctly with negative exponentiation. Finally, the mesh function is used to visualize the surface plot, allowing for a clear representation of the 3D data.
Ann_Hope
Messages
2
Reaction score
0
Hi all
I'm new to matlab/scilab. I want to draw a 3D surface using z = cos(x+y)*cos(3x-y)+cos(x-y)*sin(x+3y)+5e^(x2+y2)/8

I typed "Z=cos(x+y)*cos(3*x-y)+cos(x-y)*sin(x+3*y)+5*exp(-(x.^2+y.^2)/8);" into matlab, but is says "Inconsistent multiplication".

I would appreciate anyone who could help me check the problem and give me an advice.

Thanks all!
 
Physics news on Phys.org
a) how have you defined X and Y
b) I'd use mesh:

example said:
figure
[X,Y] = meshgrid(-8:.5:8); %<------------HERE they define X and Y
R = sqrt(X.^2 + Y.^2) + eps;
Z = sin(R)./R;
mesh(X,Y,Z) %<-----------THIS is the MATLAB function that turns all those values into a visual plot
example from http://www.mathworks.com/help/techdoc/ref/mesh.html with comments by me
 
Back
Top