tring to plot the 3d and contour levels of a function
1 view (last 30 days)
Show older comments
the function is z(x,y) = cos(2y-x)sin(2x)
with the range of x and y values mentioned in the code.
my code:
clc
clear
function [z]= contour(x,y)
x=[-pi:0.1:pi./2]
y=[-pi:0.1:pi]
z = cos(2y-x).*sin(2x)
end
[xx,yy]=meshgrid(x,y)
zz = cos(2y-x).*sin(2x)
figure
surf(xx,yy,zz)
xlabel('X')
ylabel('Y')
zlable('Z')
shading interp
colorbar
when i run it in the command window it says:
Error: File: contour.m Line: 6 Column: 10
Invalid expression. Check for missing multiplication operator, missing or
unbalanced delimiters, or other syntax error. To construct matrices, use
brackets instead of parentheses.
-this refers to this line of code:
z = cos(2y-x).*sin(2x)
0 Comments
Accepted Answer
madhan ravi
on 26 Jan 2019
clc
clear
x=-pi:0.1:pi/2
y=-pi:0.1:pi;
[xx,yy]=meshgrid(x,y)
zz = cos(2*yy-x).*sin(2*xx);
% ^------------^------ missed it
figure
surf(xx,yy,zz)
xlabel('X')
ylabel('Y')
zlabel('Z')
shading interp
colorbar
0 Comments
More Answers (0)
See Also
Categories
Find more on Lighting, Transparency, and Shading in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!