Ask Your Question
0

function minimize cannot solve Lagrange Multipliers problem.

asked 2014-07-03 03:35:21 +0100

Gregory Bard gravatar image

updated 2014-07-04 01:22:44 +0100

calc314 gravatar image

I've tried all sorts of initial conditions but this just won't converge. It is an easy Lagrange multipliers problem.

var("y z L") 
F(x, y, z, L) = (x-3)^2 +  (y-1)^2 +  (z + 1)^2 +  L*(x^2 +  y^2 +  z^2 - 4)  
minimize(F, [4, 3, 2, 1], algorithm='ncg' )

Any thoughts? Are there ways of forcing it to use more iterations, or something??

edit retag flag offensive close merge delete

Comments

1

It appears to have worked for me in SMC. Here is the output: Optimization terminated successfully. Current function value: 2.032982 Iterations: 3 Function evaluations: 57 Gradient evaluations: 3 Hessian evaluations: 3 (1.48641364243, 0.860982992316, 0.536302359521, 0.251059261969)

calc314 gravatar imagecalc314 ( 2014-07-03 14:30:17 +0100 )edit
1

When I input the second line I get SyntaxError. With plus signs inserted I also get the succesful result. This is Sage-6.3beta5. SMC is Sage-6.2. Which version is your question about?

rws gravatar imagerws ( 2014-07-03 14:58:22 +0100 )edit

rws, I'm not sure where the plus signs went. They definitely belong. It must have been an error during cut-and-paste. I was using the Sage Single-Cell Server.

Gregory Bard gravatar imageGregory Bard ( 2014-07-03 22:49:13 +0100 )edit

calc314, I'm sorry, but that's not correct. See where it says "Current function value: 2.032982"? That should be zero. Also, it does not match the symbolic solution at all. Perhaps this is a bug, and minimize should give an error message, since the minimum wasn't reached?

Gregory Bard gravatar imageGregory Bard ( 2014-07-03 22:52:17 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2014-07-04 02:56:15 +0100

calc314 gravatar image

I've done a bit of digging. You can set the max number of iterations and the tolerance.

minimize(F, [4,3,2,1], algorithm='ncg', avextol=10^(-30) , maxiter =10000 )

These get passed to scipy. However, this does not resolve your issue.

I agree with your symbolic approach! Here a different way to code it:

soln=solve(list(F.gradient()),[x,y,z,L])
edit flag offensive delete link more
1

answered 2014-07-03 22:48:04 +0100

Gregory Bard gravatar image

%% step one: var("y z L")

F(x, y, z, L) = (x-3)^2 + (y-1)^2 + (z+1)^2 + L*(x^2 + y^2 + z^2 - 4)

derivative(F)

%% step two:

eqn1= 2Lx + 2*x - 6 == 0

eqn2= 2Ly + 2*y - 2 == 0

eqn3= 2Lz + 2*z + 2 == 0

eqn4= x^2 + y^2 + z^2 - 4 == 0

solve( [eqn1, eqn2, eqn3, eqn4], [x, y, z, L] )

%% correct answer obtained: [[x == -6/11sqrt(11), y == -2/11sqrt(11), z == 2/11sqrt(11), L == -1/2sqrt(11) - 1],

[x == 6/11sqrt(11), y == 2/11sqrt(11), z == -2/11sqrt(11), L == 1/2sqrt(11) - 1]]

%% moral of the story: if symbolic methods work fine, why bother with numerical methods?! ;-)

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2014-07-03 03:35:21 +0100

Seen: 1,950 times

Last updated: Jul 04 '14