[matlab] something wrong with my code

  • Context: MATLAB 
  • Thread starter Thread starter Ann_Hope
  • Start date Start date
  • Tags Tags
    Code Matlab
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 2K views
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