How to plot level curves

46 vues (au cours des 30 derniers jours)
Irene Zhou
Irene Zhou le 23 Nov 2020
Réponse apportée : VBBV le 31 Août 2024
I have an equation Z = exp(-0.5.*((X-800)./40).^2).*cos(2*pi.*Y*1000./X).
I want to plot level curves of Y from -100 to 100 against X from 700 to 900 for Z = -1 to 1. The graph is supposed to look like the one below.
I have tried surf but it's ignoring the axis limits I set. I also don't know how to set Z to different values.
[X,Y] = meshgrid(700:1:900,-100:1:100);
Z = exp(-0.5.*((X-800)./40).^2)*cos(2*pi.*Y*1000./X);
surf(Z)
Any help is appreciated!

Réponses (1)

VBBV
VBBV le 31 Août 2024
@Irene Zhou there is a missing element wise product operator for the equation in your code.
[X,Y] = meshgrid(linspace(700,900,100),linspace(-100,100,100));
Z = exp(-0.5.*((X-800)./40).^2).*cos(2*pi.*Y*1000./X);
% missed a element wise product operator
levels = 50;
contour(X,(Y),Z,levels)
colormap jet

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by