tring to plot the 3d and contour levels of a function

1 次查看(过去 30 天)
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)

采纳的回答

madhan ravi
madhan ravi 2019-1-26
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 个)

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by