I need help finding critical values of my function

4 次查看(过去 30 天)
My function is: Could you please hlp me find code to solve for its critical points? Whenever I put it into matlab its unable to find the points.
f(x,y)= (100/((3*x+13)^2+(3*y+2)^2+(13+2))) - ((2*100)/((3*x+5)^2+(3*y-5)^2+10))-((3*100)/((3*x+13)^2+(3*y-5)^2+18))+((4*100)/((3*x-5)^2+(3*y-2)^2+7));

回答(1 个)

Stephan
Stephan 2018-8-4
Hi,
use fsolve on the derivates of your function. Then give an educated guess for the initial value of every extremum you are interested in:
% This part is only needed to plot the function
syms x y
a= 13;
b= 5;
c=2;
d=5;
p = 4*(a+b+c+d);
f(x,y)= (p./((3*x+a).^2+(3*y+c).^2+(a+c)))...
-(2*p./((3*x-b).^2+(3*y+d).^2+(b+d)))...
-(3*p./((3*x+a).^2+(3*y-d).^2+(a+d)))...
+(4*p./((3*x-b).^2+(3*y-c).^2+(b+c)));
% The interesting part starts here
% Find the x,y values for the Maximum
x0_high = [2 1];
sol_high = fsolve(@derivates, x0_high);
% Find the x,y values for the Minimum #1
x0_low_1 = [2 -2];
sol_low_1 = fsolve(@derivates, x0_low_1);
% Find the x,y values for the Minimum #2
x0_low_2 = [-5 2];
sol_low_2 = fsolve(@derivates, x0_low_2);
% Plot function and found extrema. % To see the minima in
% the plot turn it, to see it from the bottom
fsurf(f,[-10,10]);
hold on
colormap(jet);
% Plot the found point for the Maximum
scatter3(sol_high(1), sol_high(2), f(sol_high(1),sol_high(2)),'ob', 'LineWidth', 3)
% Plot the found point for the Minimum #1
scatter3(sol_low_1(1), sol_low_1(2), f(sol_low_1(1),sol_low_1(2)),'or', 'LineWidth', 3)
% Plot the found point for the Minimum #2
scatter3(sol_low_2(1), sol_low_2(2), f(sol_low_2(1),sol_low_2(2)),'or', 'LineWidth', 3)
hold off
% Define the function that should be solved here. This is the
% hint - fsolve minimizes systems of nonlinear equations of
% the form F(x) = 0 --> Your derivates should be zero for an
% extremum. Therefore get the dervates, which you can calculate
% without any problems from the symbolic function and get
% numeric functions for your fx and fy. Once you have them,
% replace x by x(1) and y by x(2). This is all i have done,
% to solve the problem. The only trick is giving good guesses
% to the initial values x0 - which can be found by looking at
% the function plot.
function F = derivates(x)
F(1) = 1.0./(x(1).*-1.0e1-x(2).*4.0+x(1).^2.*3.0+x(2).^2.*3.0+1.2e1).^2.*1.0./(x(1).*-1.0e1+x(2).*1.0e1+x(1).^2.*3.0+x(2).^2.*3.0+2.0e1).^2.*1.0./(x(1).*7.8e1+x(2).*1.2e1+x(1).^2.*9.0+x(2).^2.*9.0+1.88e2).^2.*1.0./(x(1).*7.8e1-x(2).*3.0e1+x(1).^2.*9.0+x(2).^2.*9.0+2.12e2).^2.*(x(1).*-1.33528446976e11-x(2).*3.23205188096e12-x(1).^2.*x(2).^2.*1.80827531136e11+x(1).^2.*x(2).^3.*2.91665664e8+x(1).^3.*x(2).^2.*2.10529217664e11+x(1).^2.*x(2).^4.*1.77250032e8+x(1).^3.*x(2).^3.*1.20922932672e11+x(1).^4.*x(2).^2.*1.63437102e11+x(1).^2.*x(2).^5.*9.151784352e9+x(1).^3.*x(2).^4.*2.3286118464e10+x(1).^4.*x(2).^3.*6.7802167152e10+x(1).^5.*x(2).^2.*5.0806762704e10+x(1).^2.*x(2).^6.*1.103321088e9+x(1).^3.*x(2).^5.*1.4486349744e10+x(1).^4.*x(2).^4.*1.1252940228e10+x(1).^5.*x(2).^3.*2.894281632e10+x(1).^6.*x(2).^2.*1.0473694632e10+x(1).^2.*x(2).^7.*7.94860776e8+x(1).^3.*x(2).^6.*8.70478488e8+x(1).^4.*x(2).^5.*6.197538096e9+x(1).^5.*x(2).^4.*2.82083634e9+x(1).^6.*x(2).^3.*8.681812632e9+x(1).^7.*x(2).^2.*2.237073552e9-x(1).^2.*x(2).^8.*5.8970268e7+x(1).^3.*x(2).^7.*4.80055248e8+x(1).^4.*x(2).^6.*2.29884318e8+x(1).^5.*x(2).^5.*1.491262812e9+x(1).^6.*x(2).^4.*6.41482092e8+x(1).^7.*x(2).^3.*1.508295168e9+x(1).^8.*x(2).^2.*5.58426393e8+x(1).^2.*x(2).^9.*7.381125e6-x(1).^3.*x(2).^8.*3.9366e6+x(1).^4.*x(2).^7.*9.073863e7+x(1).^5.*x(2).^6.*6.121413e7+x(1).^6.*x(2).^5.*1.6671501e8+x(1).^7.*x(2).^4.*1.3030146e8+x(1).^8.*x(2).^3.*1.21345695e8+x(1).^9.*x(2).^2.*9.9694395e7-x(1).^2.*x(2).^10.*1.062882e6+x(1).^3.*x(2).^9.*2.95245e5+x(1).^4.*x(2).^8.*2.657205e6+x(1).^5.*x(2).^7.*5.9049e5+x(1).^6.*x(2).^6.*1.062882e7+x(1).^7.*x(2).^5.*5.9049e5+x(1).^8.*x(2).^4.*1.3286025e7+x(1).^9.*x(2).^3.*2.95245e5+x(1).^10.*x(2).^2.*7.440174e6-x(1).*x(2).*1.468880331264e12-x(1).*x(2).^2.*8.28235051776e11+x(1).^2.*x(2).*5.07038485248e11-x(1).*x(2).^3.*4.59252951552e11+x(1).^3.*x(2).*5.40627457536e11-x(1).*x(2).^4.*5.249375424e10+x(1).^4.*x(2).*5.7381994944e10-x(1).*x(2).^5.*3.0201424128e10+x(1).^5.*x(2).*2.403999648e9-x(1).*x(2).^6.*3.8129616e7+x(1).^6.*x(2).*2.4780630672e10-x(1).*x(2).^7.*5.25078288e8+x(1).^7.*x(2).*1.3931388288e10-x(1).*x(2).^8.*1.98290916e8+x(1).^8.*x(2).*3.61130562e9-x(1).*x(2).^9.*8.516178e6+x(1).^9.*x(2).*5.05603782e8-x(1).*x(2).^10.*7.696053e6+x(1).^10.*x(2).*3.1866777e7+x(1).*x(2).^11.*5.9049e4+x(1).^11.*x(2).*5.9049e4+x(1).^2.*5.744419328e11+x(1).^3.*1.15004841984e11-x(1).^4.*2.4410921472e10+x(1).^5.*1.0675027584e10+x(1).^6.*1.9809183744e10+x(1).^7.*6.938244864e9+x(1).^8.*1.366017696e9+x(1).^9.*4.85006616e8+x(1).^10.*1.6559964e8+x(1).^11.*2.6847612e7+x(1).^12.*1.594323e6-x(2).^2.*1.35987270016e12-x(2).^3.*9.512079552e11-x(2).^4.*1.69992437184e11-x(2).^5.*1.14589320192e11-x(2).^6.*1.398593952e10-x(2).^7.*7.99182288e9-x(2).^8.*1.041942204e9-x(2).^9.*3.32170308e8-x(2).^10.*4.0199247e7-x(2).^11.*6.121413e6-x(2).^12.*5.31441e5-2.70806226944e12).*(-8.0e2./3.0);
F(2) = 1.0./(x(1).*-1.0e1-x(2).*4.0+x(1).^2.*3.0+x(2).^2.*3.0+1.2e1).^2.*1.0./(x(1).*-1.0e1+x(2).*1.0e1+x(1).^2.*3.0+x(2).^2.*3.0+2.0e1).^2.*1.0./(x(1).*7.8e1+x(2).*1.2e1+x(1).^2.*9.0+x(2).^2.*9.0+1.88e2).^2.*1.0./(x(1).*7.8e1-x(2).*3.0e1+x(1).^2.*9.0+x(2).^2.*9.0+2.12e2).^2.*(x(1).*-3.238953472e12+x(2).*3.873232654336e12+x(1).^2.*x(2).^2.*1.533112971264e12+x(1).^2.*x(2).^3.*2.317831842816e12+x(1).^3.*x(2).^2.*4.6093833216e10+x(1).^2.*x(2).^4.*1.02211569792e12+x(1).^3.*x(2).^3.*1.008555411456e12+x(1).^4.*x(2).^2.*8.6593520448e10+x(1).^2.*x(2).^5.*1.98512617536e11+x(1).^3.*x(2).^4.*4.39636408704e11+x(1).^4.*x(2).^3.*2.79092739456e11+x(1).^5.*x(2).^2.*1.40617933632e11+x(1).^2.*x(2).^6.*8.964868752e10+x(1).^3.*x(2).^5.*7.0256844288e10+x(1).^4.*x(2).^4.*1.41070166352e11+x(1).^5.*x(2).^3.*5.6303900928e10+x(1).^6.*x(2).^2.*5.3956684224e10+x(1).^2.*x(2).^7.*8.300032416e9+x(1).^3.*x(2).^6.*3.032861616e10+x(1).^4.*x(2).^5.*1.8439979184e10+x(1).^5.*x(2).^4.*3.3225883776e10+x(1).^6.*x(2).^3.*1.3672354176e10+x(1).^7.*x(2).^2.*9.119405088e9+x(1).^2.*x(2).^8.*2.387127996e9+x(1).^3.*x(2).^7.*2.725596864e9+x(1).^4.*x(2).^6.*5.724498744e9+x(1).^5.*x(2).^5.*4.471032816e9+x(1).^6.*x(2).^4.*4.618261656e9+x(1).^7.*x(2).^3.*3.235780224e9+x(1).^8.*x(2).^2.*7.27772364e8+x(1).^2.*x(2).^9.*1.3896198e8+x(1).^3.*x(2).^8.*4.7908422e8+x(1).^4.*x(2).^7.*5.5427328e8+x(1).^5.*x(2).^6.*6.5426292e8+x(1).^6.*x(2).^5.*8.306226e8+x(1).^7.*x(2).^4.*3.503574e8+x(1).^8.*x(2).^3.*5.5348596e8+x(1).^9.*x(2).^2.*2.322594e7+x(1).^2.*x(2).^10.*8.26686e5+x(1).^3.*x(2).^9.*4.251528e7+x(1).^4.*x(2).^8.*1.476225e6+x(1).^5.*x(2).^7.*8.503056e7+x(1).^6.*x(2).^6.*1.18098e6+x(1).^7.*x(2).^5.*8.503056e7+x(1).^8.*x(2).^4.*2.95245e5+x(1).^9.*x(2).^3.*4.251528e7-x(1).^10.*x(2).^2.*1.18098e5+x(1).*x(2).*8.822107136e10+x(1).*x(2).^2.*3.866813955072e12-x(1).^2.*x(2).*1.283635190784e12+x(1).*x(2).^3.*3.505514323968e12-x(1).^3.*x(2).*3.17988744192e11+x(1).*x(2).^4.*1.722868144128e12+x(1).^4.*x(2).*1.08586296576e11+x(1).*x(2).^5.*3.97325523456e11+x(1).^5.*x(2).*5.1682126464e10+x(1).*x(2).^6.*1.88218422144e11+x(1).^6.*x(2).*1.8240520896e10+x(1).*x(2).^7.*2.1997324224e10+x(1).^7.*x(2).*8.044380864e9+x(1).*x(2).^8.*8.413371504e9+x(1).^8.*x(2).*3.109284144e9+x(1).*x(2).^9.*6.17626296e8+x(1).^9.*x(2).*8.72717976e8+x(1).*x(2).^10.*1.26207396e8+x(1).^10.*x(2).*1.38332124e8+x(1).*x(2).^11.*8.503056e6+x(1).^11.*x(2).*8.503056e6+x(1).^2.*7.8152449536e11-x(1).^3.*6.6547643904e11-x(1).^4.*5.0200973568e11-x(1).^5.*8.6134489344e10-x(1).^6.*4.9171536e9-x(1).^7.*7.288335936e9-x(1).^8.*6.050280096e9-x(1).^9.*2.191234032e9-x(1).^10.*3.76365204e8-x(1).^11.*2.5745364e7-x(1).^12.*5.9049e4+x(2).^2.*2.810802945024e12+x(2).^3.*2.931968710656e12+x(2).^4.*1.271715708672e12+x(2).^5.*3.5883603072e11+x(2).^6.*1.57096796544e11+x(2).^7.*1.9837478016e10+x(2).^8.*8.585485488e9+x(2).^9.*4.23123264e8+x(2).^10.*1.7675334e8+x(2).^11.*1.57464e5+x(2).^12.*1.77147e5-7.04921053184e12).*(-2.0e2./3.0);
end
This example gives you:
That way you get the points of interest. Here marked in red (minima) and blue (maximum) for better contrast.
Best regards
Stephan

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by