Reputation: 49
So I'm given this equation x + e^(x^2) + e^(y^2) = r
and I would like to plot it for r = [1.5, 4]
.
My work:
[X,Y] = meshgrid(-1.5:0.1:1.5,-1.5:0.1:1.5);
Z = X + exp(X^2) + exp(Y^2);
hold on;
[C,h]=contour(X,Y,Z,1.5:0.1:4);
clabel(C,h)
hold off;
but I only get straight lines, no circles. Please help.
Upvotes: 2
Views: 48
Reputation: 73176
You missed the .
in .^
for element-wise power operation. Replace the second row with the following, and the contour plot will yield the sought-after level curves
Z = X + exp(X.^2) + exp(Y.^2);
Upvotes: 4