# 3 questions in one about exploiting the result of an optimization

This is an incredible result of SageMath since one is obliged to help Mathematica to obtain the result

 var('A, x, y, l, alpha, beta, R, p_x, p_y');
U= A*x^(alpha)*y^(beta);
show(U)
D = p_x*x + p_y*y;
show(D)
show(U)
solve(D==R, y)
L = U-l*(D-R)
show(L)
L_x= L.diff(x)
show(L_x)
L_y= L.diff(y)
show(L_y)
L_lambda= L.diff(l)
show(L_l)
z=solve([L_x==0, L_y==0, L_l==0,], x, y, l)
show(z)
x1=z.right()
show(x1)
y1=z.right()
show(y1)
U1=U.subs(x=x1,y=y1)
show(U1)


But I would ameliorate the presentation :

1) How can I substitute greek $\lambda$ to l in the code ?

2) The final result should be simplified because there are possible factorizations ?

3) How can I, without rewriting, all the code add the hypothesis $\alpha+ \beta =1$ ?

4) how to have the results automaticaly written in LaTeX without using show()

A great hand shake for the one who will help me on those maters.

edit retag close merge delete

To the moderator : I have tried to ameliorate my English but the result was not saved.

Sort by » oldest newest most voted

Regarding 2, which factorization would you expect ?

Regarding 3, you ar lucky because in the tree of the representation of the expression, alpha+beta appears as subtrees, so the following works:

sage: U1.subs({alpha+beta:1})
A*(R*alpha/p_x)^alpha*(R*beta/p_y)^beta


Regarding 4, if you are using jupyter notebook, you can add the following in the first cell:

%display latex

more