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.Sun, 03 May 2020 20:42:27 +0200Solving Lagrangians in Sagehttps://ask.sagemath.org/question/51241/solving-lagrangians-in-sage/I have been running the following Sage code on cocalc.com to solve a standard utility maximization problem that is in an intermediate microeconomics course. However I'm having difficulty solving these problems in the context of Sage.
Below is the code that I have run to solve the problem and so far I believe it's correct.
x, y, l = var('x, y, l')
U = x^0.7 * y^0.3; U
m = 2*x+2*y; m
solve(m == 4000, y)
L = U - l * (m - 4000); L
dLdx = L.diff(x); dLdx
dLdy = L.diff(y); dLdy
dLdl = L.diff(l); dLdl
solve([dLdx == 0, dLdy == 0, dLdl == 0], x, y, l)
All my code seems to be running fine, however the last line of:
solve([dLdx == 0, dLdy == 0, dLdl == 0], x, y, l)
is not outputting the final demand equations. Is there any reason why this is happening?Sun, 03 May 2020 08:55:31 +0200https://ask.sagemath.org/question/51241/solving-lagrangians-in-sage/Comment by slelievre for <p>I have been running the following Sage code on <a href="http://cocalc.com">cocalc.com</a> to solve a standard utility maximization problem that is in an intermediate microeconomics course. However I'm having difficulty solving these problems in the context of Sage.</p>
<p>Below is the code that I have run to solve the problem and so far I believe it's correct.</p>
<pre><code>x, y, l = var('x, y, l')
U = x^0.7 * y^0.3; U
m = 2*x+2*y; m
solve(m == 4000, y)
L = U - l * (m - 4000); L
dLdx = L.diff(x); dLdx
dLdy = L.diff(y); dLdy
dLdl = L.diff(l); dLdl
solve([dLdx == 0, dLdy == 0, dLdl == 0], x, y, l)
</code></pre>
<p>All my code seems to be running fine, however the last line of:</p>
<pre><code>solve([dLdx == 0, dLdy == 0, dLdl == 0], x, y, l)
</code></pre>
<p>is not outputting the final demand equations. Is there any reason why this is happening?</p>
https://ask.sagemath.org/question/51241/solving-lagrangians-in-sage/?comment=51259#post-id-51259Regarding your note for mods: visit your profile page and find all your questions and answers.
To visit your profile page, click on your name near this question. or at the very top left from any page.Sun, 03 May 2020 20:42:27 +0200https://ask.sagemath.org/question/51241/solving-lagrangians-in-sage/?comment=51259#post-id-51259Answer by tmonteil for <p>I have been running the following Sage code on <a href="http://cocalc.com">cocalc.com</a> to solve a standard utility maximization problem that is in an intermediate microeconomics course. However I'm having difficulty solving these problems in the context of Sage.</p>
<p>Below is the code that I have run to solve the problem and so far I believe it's correct.</p>
<pre><code>x, y, l = var('x, y, l')
U = x^0.7 * y^0.3; U
m = 2*x+2*y; m
solve(m == 4000, y)
L = U - l * (m - 4000); L
dLdx = L.diff(x); dLdx
dLdy = L.diff(y); dLdy
dLdl = L.diff(l); dLdl
solve([dLdx == 0, dLdy == 0, dLdl == 0], x, y, l)
</code></pre>
<p>All my code seems to be running fine, however the last line of:</p>
<pre><code>solve([dLdx == 0, dLdy == 0, dLdl == 0], x, y, l)
</code></pre>
<p>is not outputting the final demand equations. Is there any reason why this is happening?</p>
https://ask.sagemath.org/question/51241/solving-lagrangians-in-sage/?answer=51254#post-id-51254Sage symbolics handles fractional powers better than numerical ones, so if you replace
U=x^0.7*y^0.3;U
with
U=x^(7/10)*y^(3/10);U
it seems to work much better.
Sun, 03 May 2020 15:56:21 +0200https://ask.sagemath.org/question/51241/solving-lagrangians-in-sage/?answer=51254#post-id-51254