Problem with minimize_constrained

27 views
Skip to first unread message

Nicola Sottocornola

unread,
Aug 19, 2024, 6:35:29 AM8/19/24
to sage-support
Dear all,

we want to find the maximum of the function G over [0,1]x[0,1]. The code below gives 0 which is clearly wrong. 

Using instead

sage: minimize_constrained(-G, [[0, 1], [0, 1]],[1/2, 1/2])
seems to provide the right answer...

var('x,y') c1(x,y)=x c2(x,y)=y c3(x,y)=1-x c4(x,y)=1-y G(x,y) = -(56*x^2*y^2 - 4*x^2*y - 4*x*y^2 - 4*x^2 - x*y - 4*y^2 - x - y - 1)*(x - 1)*(y - 1) M = minimize_constrained(-G(x,y), [c1(x,y),c2(x,y),c3(x,y),c4(x,y)],[0.5,0.5]) print(G(M[0],M[1]))

Emmanuel Charpentier

unread,
Aug 19, 2024, 11:07:01 AM8/19/24
to sage-support

I filed this issue for your question.

An analytical solution :

# Potential extrema : points where all first derivatives are zero. PE = [{u:d[u].n() for u in d.keys()} for d in solve([G(x, y).diff(u) for u in (x, y)], (x, y), solution_dict=True)] # Actual values of G var("val") Vals=[d|{val:G(d[x],d[y]).n()} for d in PE] # Actual maxima [d for d in Vals if d[val]==(Max:=max([d[val] for d in Vals]))]

gives

[{x: 0.500000000000000, y: 0.000000000000000, val: 1.25000000000000}, {x: 0.000000000000000, y: 0.500000000000000, val: 1.25000000000000}]

HTH,

Reply all
Reply to author
Forward
0 new messages