Why do my axis change dimensioins?
1 view (last 30 days)
Show older comments
Hi All, this code is supposed to plot a 3D surface and a contour plot of the function with wells at (-2, 2) and (3, -1). However, when I run the code, firstly, the wells are not in the right places, and the dimensions of the axis change as my inputs for x and y change (ie the position of the wells change). What am I doing wrong?
Here is my code,
function M = landscape(x, y)
M = H1(x, y) + H2(x, y);
function h1 = H1(x, y)
R1 = 2;
s1 = [-2;2];
n1 = 2;
h1 = (1./(1+(R1./sqrt((x-s1(1)).^2+(y(:)-s1(2)).^2)).^n1));
end
function h2 = H2(x, y)
R2 = 1;
s2 = [3;-1];
n2 = 1;
h2 = (1./(1+(R2./sqrt((x-s2(1)).^2+(y(:)-s2(2)).^2)).^n2));
end
subplot(1, 2, 1)
surf(M)
subplot(1, 2, 2)
contour(M)
end
And two different graphs the first with x and y -5:5 and the second with x and y -10:10
Notice how the position of the wells change?
0 Comments
Accepted Answer
Steven Lord
on 19 Oct 2019
What happens, according to the documentation, when you call surf with one input argument? What does surf use for the X and Y coordinates at which to place the points that make up the surface?
Try calling surf with three input arguments instead.
The same applies to the contour function. You called it with one input when you should be calling it with three.
More Answers (0)
See Also
Categories
Find more on Contour Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!