Find critical points of a function with two variables
18 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I'm trying to find critical points to this function but it is so long that when i try to run this:
syms x y z
eqns = (120./((3*x+12).^2+(3*y+8).^2+20))-(240./((3*x-9).^2+(3*y+1).^2+10))-(360./((3*x+12).^2+(3*y-1).^2+13))+(480./((3*x-9).^2+(3*y-8).^2+17));
dx = diff(eqns,x)== 0 %=(240(18x-54))/((3x-9)^2+(3y+1)^2+10)^2-(480(18x 54))/((3x-9)^2+(3y-8)^2+17)^2+(360(18x+72))/((3x+12)^2+(3y-1)^2+13)^2-(120(18x+72))/((3x+12)^2+(3y+8)^2+20)^2
dy = diff(eqns,y)== 0% =(240(18y+6))/((3x-9)^2+(3y+1)^2+10)^2+(360(18y-6))/((3x+12)^2+(3y-1)^2+13)^2-(480(18y-48))/((3x-9)^2+(3y-8)^2+17)^2-(120(18y+48))/((3x+12)^2+(3y+8)^2+20)^2
[xcr,ycr]=solve(dx,dy); [xcr,ycr]
I get a spinning blue ball that goes forever
the domain is -10<x<10 -10<y<10
4 commentaires
Réponses (1)
Walter Roberson
le 31 Juil 2017
The key is two-fold:
syms x y real
eqns = (120./((3*x+12).^2+(3*y+8).^2+20))-(240./((3*x-9).^2+(3*y+1).^2+10))-(360./((3*x+12).^2+(3*y-1).^2+13))+(480./((3*x-9).^2+(3*y-8).^2+17));
dx = diff(eqns,x);
dy = diff(eqns,y);
sol = vpasolve([dx,dy])
This is fairly fast, and gives sol.x and sol.y with 6 solutions each. You can then
subs(dx,{x,y},{sol.x,sol.y})
subs(dy,{x,y},{sol.x,sol.y})
and see that the derivatives are very close to 0. The exception is at
x = -4.4546625928986563919737615802286
y = -9.5289449194003238929219876399778
which is a point at which the derivatives are steep enough to give numeric problems. This also happens to be the location that my other tests had been finding. It appears that point is a saddle point.
FF = subs(eqns,sol);
fsurf(eqns,[-10 10 -10 10]);
hold on
scatter3(sol.x,sol.y,FF,30,'r+')
You can see two local minima, two local maxima, and 2 saddle points. (I would not be surprised if there were more saddle points that this process does not locate.)
0 commentaires
Voir également
Catégories
En savoir plus sur Linear Algebra dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!