If you realy need the exact solution then you can tray something like
that
var('x,y,lam,x4,y2')
assume(x4>0)
assume(y2>0)
L= x+2*y -lam*(16-2*x^(1/4)*y^(1/2))
eq1=numerator(factor(L.diff(x)))
eq1=eq1(y=y2^2,x=x4^4).full_simplify()
eq2=numerator(factor(L.diff(y)))
eq2=eq2(y=y2^2,x=x4^4).full_simplify()
eq3=numerator(factor(L.diff(lam)))
eq3=eq3(y=y2^2,x=x4^4).full_simplify()
s=solve([eq1==0,eq2==0,eq3==0], x4,y2,lam)
print [[(sol[0].rhs())^4,(sol[1].rhs())^2] for sol in s if
sol[0].rhs()>0 and sol[1].rhs()>0]
[16,16]]
But the numerical approach is simpler:
sage: from scipy.optimize import fmin_slsqp
sage: fmin_slsqp(lambda x:x[0]+2*x[1], [2.0, 2.0], eqcons=[lambda x:
16.0-2*x[0]**0.25*x[1]**0.5])
Optimization terminated successfully. (Exit mode 0)
Current function value: 47.9999996459
Iterations: 9
Function evaluations: 36
Gradient evaluations: 9
array([ 16.0000018 , 15.99999893])
Compare the picture:
var('x y z')
p1=implicit_plot3d(16-2*x^(1/4)*y^(1/2),(x,0,32),(y,0,32),(z,0,100))
p2=plot3d(x+2*y,(x,0,32),(y,0,32),color='red')
(p1+p2).show()
Andrzej Chrzeszczyk
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org