Why do my axis change dimensioins?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Steven Lord
2019-10-19
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!