ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 12 Sep 2019 22:01:10 +02003 questions in one about exploiting the result of an optimizationhttps://ask.sagemath.org/question/47855/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[0])
x1=z[0][0].right()
show(x1)
y1=z[0][1].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.Thu, 12 Sep 2019 20:55:01 +0200https://ask.sagemath.org/question/47855/3-questions-in-one-about-exploiting-the-result-of-an-optimization/Comment by tmonteil for <p>This is an incredible result of SageMath since one is obliged to help Mathematica to obtain the result</p>
<pre><code> 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[0])
x1=z[0][0].right()
show(x1)
y1=z[0][1].right()
show(y1)
U1=U.subs(x=x1,y=y1)
show(U1)
</code></pre>
<p>But I would ameliorate the presentation :</p>
<p>1) How can I substitute greek $\lambda$ to l in the code ?</p>
<p>2) The final result should be simplified because there are possible factorizations ?</p>
<p>3) How can I, without rewriting, all the code add the hypothesis $\alpha+ \beta =1$ ?</p>
<p>4) how to have the results automaticaly written in LaTeX without using show()</p>
<p>A great hand shake for the one who will help me on those maters.</p>
https://ask.sagemath.org/question/47855/3-questions-in-one-about-exploiting-the-result-of-an-optimization/?comment=47862#post-id-47862You can try again.Thu, 12 Sep 2019 22:01:10 +0200https://ask.sagemath.org/question/47855/3-questions-in-one-about-exploiting-the-result-of-an-optimization/?comment=47862#post-id-47862Comment by Cyrille for <p>This is an incredible result of SageMath since one is obliged to help Mathematica to obtain the result</p>
<pre><code> 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[0])
x1=z[0][0].right()
show(x1)
y1=z[0][1].right()
show(y1)
U1=U.subs(x=x1,y=y1)
show(U1)
</code></pre>
<p>But I would ameliorate the presentation :</p>
<p>1) How can I substitute greek $\lambda$ to l in the code ?</p>
<p>2) The final result should be simplified because there are possible factorizations ?</p>
<p>3) How can I, without rewriting, all the code add the hypothesis $\alpha+ \beta =1$ ?</p>
<p>4) how to have the results automaticaly written in LaTeX without using show()</p>
<p>A great hand shake for the one who will help me on those maters.</p>
https://ask.sagemath.org/question/47855/3-questions-in-one-about-exploiting-the-result-of-an-optimization/?comment=47856#post-id-47856To the moderator : I have tried to ameliorate my English but the result was not saved.Thu, 12 Sep 2019 21:14:12 +0200https://ask.sagemath.org/question/47855/3-questions-in-one-about-exploiting-the-result-of-an-optimization/?comment=47856#post-id-47856Answer by tmonteil for <p>This is an incredible result of SageMath since one is obliged to help Mathematica to obtain the result</p>
<pre><code> 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[0])
x1=z[0][0].right()
show(x1)
y1=z[0][1].right()
show(y1)
U1=U.subs(x=x1,y=y1)
show(U1)
</code></pre>
<p>But I would ameliorate the presentation :</p>
<p>1) How can I substitute greek $\lambda$ to l in the code ?</p>
<p>2) The final result should be simplified because there are possible factorizations ?</p>
<p>3) How can I, without rewriting, all the code add the hypothesis $\alpha+ \beta =1$ ?</p>
<p>4) how to have the results automaticaly written in LaTeX without using show()</p>
<p>A great hand shake for the one who will help me on those maters.</p>
https://ask.sagemath.org/question/47855/3-questions-in-one-about-exploiting-the-result-of-an-optimization/?answer=47861#post-id-47861Regarding 1, see the answer of https://ask.sagemath.org/question/47851/optimization-under-constraint
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
Thu, 12 Sep 2019 22:00:46 +0200https://ask.sagemath.org/question/47855/3-questions-in-one-about-exploiting-the-result-of-an-optimization/?answer=47861#post-id-47861