Evaluating maxima and minima of functions of two variables
12 views (last 30 days)
Show older comments
Four small towns in a rural area wish to pool their resources to build a television station. If the towns are located at the points (-5,0), (1,7), (9,0) and (0,-8) on a rectangular map grid, where units are in miles, at what point S(x,y) should the station be located to minimize the sum of the distances from the towns, by using MATLAB Code and visualize graphically.
1 Comment
MANOJ VARMA
on 13 Jan 2022
Obtain the maximum and minimum values of f (x,y) = x4 + y4 – x2 - y2 + 1.
Accepted Answer
DGM
on 24 Dec 2021
How would you solve a minimization problem on paper? If you use the symbolic toolbox, it's basically the same.
syms x y
D = sqrt((x+5)^2 + (y-0)^2) + sqrt((x-1)^2 + (y-7)^2) ...
+ sqrt((x-9)^2 + (y-0)^2) + sqrt((x-0)^2 + (y+8)^2);
Dx = diff(D,x);
Dy = diff(D,y);
S = vpasolve([Dx==0, Dy==0],[x y]);
minlocation = double([S.x S.y])
fsurf(D,[-10 10 -10 10]); hold on
plot3(S.x,S.y,subs(D,[x y],minlocation),'*w','markersize',10)
colormap(jet)
view(-20,51)
That said, you can get a fair approximation without the symbolic tools.
N = 1000;
x = linspace(0,1,N);
y = linspace(-0.5,0.5,N).';
D = sqrt((x+5).^2 + (y-0).^2) + sqrt((x-1).^2 + (y-7).^2) ...
+ sqrt((x-9).^2 + (y-0).^2) + sqrt((x-0).^2 + (y+8).^2);
[~,idx] = min(D(:));
[r c] = ind2sub([N N],idx);
minlocation = [x(c) y(r)]
figure
surf(x,y,D); hold on
plot3(x(c),y(r),D(r,c),'*w','markersize',10)
shading flat
colormap(jet)
view(-20,51)
0 Comments
More Answers (0)
See Also
Categories
Find more on Calculus 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!