Filter löschen
Filter löschen

Plotting contours with additional condition

7 Ansichten (letzte 30 Tage)
Theo
Theo am 13 Jul. 2011
Let f(z) be a complex function. Suppose I wanted to plot the contours where the imaginary part, imag(f(z)) = 0, but the real part positive. An example code would be
% Mesh
x = linspace(-2, 2, 50);
y = linspace(-2, 2, 50);
[xmat, ymat] = meshgrid(x, y);
z = xmat + 1i*ymat;
% Function
f = sqrt(z);
% Contour
[C, h] = contour(x, y, imag(f), [0 0]);
This gives me the contours with imag(f) == 0. However, I'd like to only plot contours with imag(f) == 0 && real(f) >= 0. Is there an easy way to do this?

Antworten (1)

Rick Rosson
Rick Rosson am 13 Jul. 2011
Please try the following:
thresh = 0.02;
idx = ( (abs(imag(f)) < thresh) & (real(f)>=0) );
[C, h] = contour(x, y, idx, [ 1 1 ]);
This approach is highly dependent on the choice of value for thresh. So it's not a perfect solution, but it is a possibility.
HTH.

Kategorien

Mehr zu Contour Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by