[matlab] something wrong with my code

  • Context: MATLAB 
  • Thread starter Thread starter Ann_Hope
  • Start date Start date
  • Tags Tags
    Code Matlab
Click For Summary
SUMMARY

The discussion centers on a MATLAB error encountered while attempting to create a 3D surface plot using the equation z = cos(x+y)*cos(3x-y)+cos(x-y)*sin(x+3y)+5e^(x^2+y^2)/8. The error "Inconsistent multiplication" arises due to improper variable definitions for X and Y. The solution involves using the meshgrid function to define X and Y, followed by the mesh function to visualize the surface plot correctly.

PREREQUISITES
  • Understanding of MATLAB syntax and functions
  • Familiarity with the meshgrid function in MATLAB
  • Knowledge of 3D plotting techniques in MATLAB
  • Basic understanding of mathematical functions and operations
NEXT STEPS
  • Learn how to use MATLAB's meshgrid function for creating grid coordinates
  • Explore the MATLAB mesh function for 3D surface plotting
  • Research error handling in MATLAB to troubleshoot common issues
  • Study mathematical functions and their graphical representations in MATLAB
USEFUL FOR

Beginner MATLAB users, educators teaching mathematical visualization, and anyone interested in 3D plotting techniques in MATLAB.

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
 

Similar threads

Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 6 ·
Replies
6
Views
4K