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)
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!