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.Mon, 20 Jul 2020 02:53:35 +0200Unable to simplify variable completelyhttps://ask.sagemath.org/question/52537/unable-to-simplify-variable-completely/
In solving the following hicksian demands in this problem and so far the proceedure works great.
x1, x2, l, p1, p2, a, b, R= var('x1, x2, l, p1, p2, a, b, R')
U = x1^a*x2^b
m = p1*x1+p2*x2;
L = m+ l * (R-U);
dLdx = L.diff(x1);
dLdy = L.diff(x2);
dLdl = L.diff(l);
step1=solve([dLdx == 0, dLdy == 0, dLdl == 0], p1, p2, R)
step2=solve((p1/p2).subs(step1)==p1/p2, x1)
good2step3 = solve((U/R).subs(step2).log().log_expand()==0, x2)
good1step4=solve(step2[0].subs(good2step3).canonicalize_radical(),x1)
however I note that I dont get such a clean result for `good2step3`, though algebraically correct its not completely simplified. I've tried `simplify_rational()` and `simplify_log` but that ends up ruining my clean solution for `x1` in `good1step4`.
Is there more I can do to clean up my solutions?Fri, 17 Jul 2020 22:04:37 +0200https://ask.sagemath.org/question/52537/unable-to-simplify-variable-completely/Answer by Juanjo for <p>In solving the following hicksian demands in this problem and so far the proceedure works great.</p>
<pre><code>x1, x2, l, p1, p2, a, b, R= var('x1, x2, l, p1, p2, a, b, R')
U = x1^a*x2^b
m = p1*x1+p2*x2;
L = m+ l * (R-U);
dLdx = L.diff(x1);
dLdy = L.diff(x2);
dLdl = L.diff(l);
step1=solve([dLdx == 0, dLdy == 0, dLdl == 0], p1, p2, R)
step2=solve((p1/p2).subs(step1)==p1/p2, x1)
good2step3 = solve((U/R).subs(step2).log().log_expand()==0, x2)
good1step4=solve(step2[0].subs(good2step3).canonicalize_radical(),x1)
</code></pre>
<p>however I note that I dont get such a clean result for <code>good2step3</code>, though algebraically correct its not completely simplified. I've tried <code>simplify_rational()</code> and <code>simplify_log</code> but that ends up ruining my clean solution for <code>x1</code> in <code>good1step4</code>.</p>
<p>Is there more I can do to clean up my solutions?</p>
https://ask.sagemath.org/question/52537/unable-to-simplify-variable-completely/?answer=52569#post-id-52569Don't expect a clean expression from the output of `solve`. Instead, print (or show) the solution by substitution and apply additional methods to simplify the expressions. In this case, you can replace the last line by
good1step4 = solve(step2[0].subs(good2step3),x1)
print("x2 =", x2.subs(good2step3).canonicalize_radical())
print("x1 =", x1.subs(good1step4).canonicalize_radical())
Mon, 20 Jul 2020 02:53:35 +0200https://ask.sagemath.org/question/52537/unable-to-simplify-variable-completely/?answer=52569#post-id-52569