Why do my axis change dimensioins?

1 visualizzazione (ultimi 30 giorni)
Dawid Brits
Dawid Brits il 19 Ott 2019
Commentato: Dawid Brits il 19 Ott 2019
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
landscape55.jpg
landscape1010.jpg
Notice how the position of the wells change?

Risposta accettata

Steven Lord
Steven Lord il 19 Ott 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.

Più risposte (0)

Categorie

Scopri di più su Contour Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by