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

3 ビュー (過去 30 日間)
Chloe St John
Chloe St John 2019 年 1 月 26 日
回答済み: madhan ravi 2019 年 1 月 26 日
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 Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by