MATLAB Answers


Why do my axis change dimensioins?

Asked by Dawid Brits on 19 Oct 2019 at 2:04
Latest activity Commented on by Dawid Brits on 19 Oct 2019 at 2:46
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));
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));
subplot(1, 2, 1)
subplot(1, 2, 2)
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?


Sign in to comment.

1 Answer

Answer by Steven Lord
on 19 Oct 2019 at 2:31
 Accepted Answer

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.

  1 Comment

Dawid Brits on 19 Oct 2019 at 2:46

Sign in to comment.