If i have a long function with multiple variables, How can i find its absolute max and absolute min ?

1 view (last 30 days)
i have this function---> f=[(268/((3*x+18)^2+(3*y+7)^2+(18+7)))-(2*(268)/((3*x-21)^2+(3*y+21)^2+(21+21)))-(3*(268)/((3*x+18)^2+(3*y-21)^2+(18+21)))+(4*(268)/((3*x-21)^2+(3*y-7)^2+(21+7))) ] I'm trying to find a away to calculate the absolute max and the absolute min. Everything i tried wont work, because my function's format does not fit their criteria.
Please help! Jerry,

Answers (1)

Star Strider
Star Strider on 2 Aug 2016
Edited: Star Strider on 2 Aug 2016
I’m not certain what you’ve tried, or the result you want. I used the Symbolic Math Toolbox to simplify your equation and turn it into a function (with simplify and matlabFunction), then used fminsearch (experimenting with several initial parameter estimates) and plotted it over an inclusive range of ‘x’ and ‘y’:
f = @(x,y)2.68e2./((x.*3.0+1.8e1).^2+(y.*3.0+7.0).^2+2.5e1)+1.072e3./((x.*3.0-2.1e1).^2+(y.*3.0-7.0).^2+2.8e1)-8.04e2./((x.*3.0+1.8e1).^2+(y.*3.0-2.1e1).^2+3.9e1)-5.36e2./((x.*3.0-2.1e1).^2+(y.*3.0+2.1e1).^2+4.2e1);
f_min = fminsearch(@(b) f(b(1),b(2)), [5; 5]);
f_max = fminsearch(@(b) -f(b(1),b(2)), [5; 5]);
x = linspace(-15, 15, 50); % Define ‘x’ Range
y = linspace(-15, 15, 50); % Define ‘y’ Range
[X,Y] = meshgrid(x,y);
figure(1)
meshc(X, Y, f(X,Y))
hold on
plot3(f_min(1), f_min(2), f(f_min(1), f_min(2)), 'vr', 'MarkerFaceColor','r')
plot3(f_max(1), f_max(2), f(f_max(1), f_max(2)), '^r', 'MarkerFaceColor','r')
hold off
grid on
view([-160 25])
Experiment with other initial parameter estimates for the function. I doubt you will arrive at a different ‘global’ maximum and minimum.
EDIT — Added plot.

Categories

Find more on Performance and Memory 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!