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, 16 Jul 2020 19:00:01 +0200Deriving a contract curve in sagehttps://ask.sagemath.org/question/52480/deriving-a-contract-curve-in-sage/Im trying to solve for the set of pareto efficent allocations using sage. So far i'm on the right track with my code of a two by two economy with consumer A and consumer B with resource constraints given by R1 and R2 for the total amount of good 1 and good 2.
xa1, xa2, xb1, xb2, a, b, R1, R2 = var('xa1, xa2, xb1, xb2, a, b, R1, R2')
Ua = xa1^a * xa2^b;
Ub = xb1^a*xb2^b;
R1=xa1+xb1;
R2=xa2+xb2;
MUa1=Ua.diff(xa1)
MUa2=Ua.diff(xa2)
MUb1=Ub.diff(xb1)
MUb2=Ub.diff(xb2)
MRSA=MUa1/MUa2
MRSB=MUb1/MUb2
solve([MRSA==MRSB],xa1)
The solution this code gives us is:
[xa1 == xa2*xb1/xb2]
I want to reduce `xa1` to be a function of `R1`,`R2` and `xb1`.
on paper this could be found by using the definitions of `R1` and `R2`.
I've tried this before by including these variables in the square brackets of the solution but with no luck. Any help is appreciated.Wed, 15 Jul 2020 23:07:14 +0200https://ask.sagemath.org/question/52480/deriving-a-contract-curve-in-sage/Answer by EconJohn for <p>Im trying to solve for the set of pareto efficent allocations using sage. So far i'm on the right track with my code of a two by two economy with consumer A and consumer B with resource constraints given by R1 and R2 for the total amount of good 1 and good 2.</p>
<pre><code>xa1, xa2, xb1, xb2, a, b, R1, R2 = var('xa1, xa2, xb1, xb2, a, b, R1, R2')
Ua = xa1^a * xa2^b;
Ub = xb1^a*xb2^b;
R1=xa1+xb1;
R2=xa2+xb2;
MUa1=Ua.diff(xa1)
MUa2=Ua.diff(xa2)
MUb1=Ub.diff(xb1)
MUb2=Ub.diff(xb2)
MRSA=MUa1/MUa2
MRSB=MUb1/MUb2
solve([MRSA==MRSB],xa1)
</code></pre>
<p>The solution this code gives us is:</p>
<pre><code>[xa1 == xa2*xb1/xb2]
</code></pre>
<p>I want to reduce <code>xa1</code> to be a function of <code>R1</code>,<code>R2</code> and <code>xb1</code>.</p>
<p>on paper this could be found by using the definitions of <code>R1</code> and <code>R2</code>.</p>
<p>I've tried this before by including these variables in the square brackets of the solution but with no luck. Any help is appreciated.</p>
https://ask.sagemath.org/question/52480/deriving-a-contract-curve-in-sage/?answer=52511#post-id-52511Managed to figure out this problem. I found that if you define your constraints in the context of the `solve()` function we get a clearer picture. The contract curve from consumer A's perspective is given by the following:
xa1, xa2, xb1, xb2, a, b, R1, R2 = var('xa1, xa2, xb1, xb2, a, b, R1, R2')
Ua = xa1^a * xa2^b;
Ub = xb1^a*xb2^b;
MUa1=Ua.diff(xa1)
MUa2=Ua.diff(xa2)
MUb1=Ub.diff(xb1)
MUb2=Ub.diff(xb2)
MRSA=MUa1/MUa2
MRSB=MUb1/MUb2
solve([MRSA==MRSB,R1==xa1+xb1,R2==xa2+xb2],xa1,xb1,xb2)
Out: [[xa1 == R1*xa2/R2, xb1 == (R1*R2 - R1*xa2)/R2, xb2 == R2 - xa2]]
If we were to conciser consumer B's perspective we have to only change the last line of code to:
solve([MRSA==MRSB,R1==xa1+xb1,R2==xa2+xb2],xa1,xb1,xa2)
Out: [[xa1 == (R1*R2 - R1*xb2)/R2, xb1 == R1*xb2/R2, xa2 == R2 - xb2]]
The reason why we need to change this last line of code is due to the nature of the solver.
Pretty happy with this result.Thu, 16 Jul 2020 19:00:01 +0200https://ask.sagemath.org/question/52480/deriving-a-contract-curve-in-sage/?answer=52511#post-id-52511Answer by Emmanuel Charpentier for <p>Im trying to solve for the set of pareto efficent allocations using sage. So far i'm on the right track with my code of a two by two economy with consumer A and consumer B with resource constraints given by R1 and R2 for the total amount of good 1 and good 2.</p>
<pre><code>xa1, xa2, xb1, xb2, a, b, R1, R2 = var('xa1, xa2, xb1, xb2, a, b, R1, R2')
Ua = xa1^a * xa2^b;
Ub = xb1^a*xb2^b;
R1=xa1+xb1;
R2=xa2+xb2;
MUa1=Ua.diff(xa1)
MUa2=Ua.diff(xa2)
MUb1=Ub.diff(xb1)
MUb2=Ub.diff(xb2)
MRSA=MUa1/MUa2
MRSB=MUb1/MUb2
solve([MRSA==MRSB],xa1)
</code></pre>
<p>The solution this code gives us is:</p>
<pre><code>[xa1 == xa2*xb1/xb2]
</code></pre>
<p>I want to reduce <code>xa1</code> to be a function of <code>R1</code>,<code>R2</code> and <code>xb1</code>.</p>
<p>on paper this could be found by using the definitions of <code>R1</code> and <code>R2</code>.</p>
<p>I've tried this before by including these variables in the square brackets of the solution but with no luck. Any help is appreciated.</p>
https://ask.sagemath.org/question/52480/deriving-a-contract-curve-in-sage/?answer=52499#post-id-52499You can't : your solution involves `xa2`, which doesn't appear in the definition of `R1` and `R2` ; `xa2` is an independent quantity.
May I suggest proofing your problem ?
**EDIT :** After typo correction, it's clearer. And CAN be solved. Let's rewrite the problem a bit:
xa1, xa2, xb1, xb2, a, b, R1, R2 = var('xa1, xa2, xb1, xb2, a, b, R1, R2')
Ua = xa1^a * xa2^b
Ub = xb1^a*xb2^b
MUa1=Ua.diff(xa1)
MUa2=Ua.diff(xa2)
MUb1=Ub.diff(xb1)
MUb2=Ub.diff(xb2)
MRSA=MUa1/MUa2
MRSB=MUb1/MUb2
Sol=solve([MRSA==MRSB],xa1)
Let's define R1 and R2 by *equations*, not assignments :
E1=R1==xa1+xb1
E2=R2==xa2+xb2
Your solution is :
sage: Sol
[xa1 == xa2*xb1/xb2]
We can solve `E1` and `E2` for `xa1` and `xa2` (thus getting tid of th`, `R2` and `xb2` :em) :
sage: solve([E1,E2],[xa1,xa2])[0]
[xa1 == R1 - xb1, xa2 == R2 - xb2]
Let(' substitute that into your solution :
sage: Sol[0].subs(solve([E1,E2],[xa1,xa2])[0])
R1 - xb1 == (R2 - xb2)*xb1/xb2
which gives us `xb1` as a function of `R1`, `R2` and `xb1` :
sage: Sol[0].subs(solve([E1,E2],[xa1,xa2])[0]).solve(xb1)
[xb1 == R1*xb2/R2]
which if I understand you correctly,is the result you sought.
HTH,Thu, 16 Jul 2020 13:54:26 +0200https://ask.sagemath.org/question/52480/deriving-a-contract-curve-in-sage/?answer=52499#post-id-52499Comment by EconJohn for <p>You can't : your solution involves <code>xa2</code>, which doesn't appear in the definition of <code>R1</code> and <code>R2</code> ; <code>xa2</code> is an independent quantity.</p>
<p>May I suggest proofing your problem ?</p>
<p><strong>EDIT :</strong> After typo correction, it's clearer. And CAN be solved. Let's rewrite the problem a bit:</p>
<pre><code>xa1, xa2, xb1, xb2, a, b, R1, R2 = var('xa1, xa2, xb1, xb2, a, b, R1, R2')
Ua = xa1^a * xa2^b
Ub = xb1^a*xb2^b
MUa1=Ua.diff(xa1)
MUa2=Ua.diff(xa2)
MUb1=Ub.diff(xb1)
MUb2=Ub.diff(xb2)
MRSA=MUa1/MUa2
MRSB=MUb1/MUb2
Sol=solve([MRSA==MRSB],xa1)
</code></pre>
<p>Let's define R1 and R2 by <em>equations</em>, not assignments :</p>
<pre><code>E1=R1==xa1+xb1
E2=R2==xa2+xb2
</code></pre>
<p>Your solution is :</p>
<pre><code>sage: Sol
[xa1 == xa2*xb1/xb2]
</code></pre>
<p>We can solve <code>E1</code> and <code>E2</code> for <code>xa1</code> and <code>xa2</code> (thus getting tid of th<code>,</code>R2<code>and</code>xb2` :em) : </p>
<pre><code>sage: solve([E1,E2],[xa1,xa2])[0]
[xa1 == R1 - xb1, xa2 == R2 - xb2]
</code></pre>
<p>Let(' substitute that into your solution :</p>
<pre><code>sage: Sol[0].subs(solve([E1,E2],[xa1,xa2])[0])
R1 - xb1 == (R2 - xb2)*xb1/xb2
</code></pre>
<p>which gives us <code>xb1</code> as a function of <code>R1</code>, <code>R2</code> and <code>xb1</code> :</p>
<pre><code>sage: Sol[0].subs(solve([E1,E2],[xa1,xa2])[0]).solve(xb1)
[xb1 == R1*xb2/R2]
</code></pre>
<p>which if I understand you correctly,is the result you sought.</p>
<p>HTH,</p>
https://ask.sagemath.org/question/52480/deriving-a-contract-curve-in-sage/?comment=52502#post-id-52502The form on paper you can solve this by subbing in our resource constraints and getting `xa1==(R1-xa1)*xb1/(R2-xb1)` further simplifying should give us `xa1==xb1*R1/R2`. I just havent figured out how to do this in sage.Thu, 16 Jul 2020 16:27:25 +0200https://ask.sagemath.org/question/52480/deriving-a-contract-curve-in-sage/?comment=52502#post-id-52502Comment by Emmanuel Charpentier for <p>You can't : your solution involves <code>xa2</code>, which doesn't appear in the definition of <code>R1</code> and <code>R2</code> ; <code>xa2</code> is an independent quantity.</p>
<p>May I suggest proofing your problem ?</p>
<p><strong>EDIT :</strong> After typo correction, it's clearer. And CAN be solved. Let's rewrite the problem a bit:</p>
<pre><code>xa1, xa2, xb1, xb2, a, b, R1, R2 = var('xa1, xa2, xb1, xb2, a, b, R1, R2')
Ua = xa1^a * xa2^b
Ub = xb1^a*xb2^b
MUa1=Ua.diff(xa1)
MUa2=Ua.diff(xa2)
MUb1=Ub.diff(xb1)
MUb2=Ub.diff(xb2)
MRSA=MUa1/MUa2
MRSB=MUb1/MUb2
Sol=solve([MRSA==MRSB],xa1)
</code></pre>
<p>Let's define R1 and R2 by <em>equations</em>, not assignments :</p>
<pre><code>E1=R1==xa1+xb1
E2=R2==xa2+xb2
</code></pre>
<p>Your solution is :</p>
<pre><code>sage: Sol
[xa1 == xa2*xb1/xb2]
</code></pre>
<p>We can solve <code>E1</code> and <code>E2</code> for <code>xa1</code> and <code>xa2</code> (thus getting tid of th<code>,</code>R2<code>and</code>xb2` :em) : </p>
<pre><code>sage: solve([E1,E2],[xa1,xa2])[0]
[xa1 == R1 - xb1, xa2 == R2 - xb2]
</code></pre>
<p>Let(' substitute that into your solution :</p>
<pre><code>sage: Sol[0].subs(solve([E1,E2],[xa1,xa2])[0])
R1 - xb1 == (R2 - xb2)*xb1/xb2
</code></pre>
<p>which gives us <code>xb1</code> as a function of <code>R1</code>, <code>R2</code> and <code>xb1</code> :</p>
<pre><code>sage: Sol[0].subs(solve([E1,E2],[xa1,xa2])[0]).solve(xb1)
[xb1 == R1*xb2/R2]
</code></pre>
<p>which if I understand you correctly,is the result you sought.</p>
<p>HTH,</p>
https://ask.sagemath.org/question/52480/deriving-a-contract-curve-in-sage/?comment=52506#post-id-52506This :
R1=xa1+xb1;
R2=xb1+xb2;
is curiously asymetric. Could you check ?Thu, 16 Jul 2020 17:37:59 +0200https://ask.sagemath.org/question/52480/deriving-a-contract-curve-in-sage/?comment=52506#post-id-52506Comment by EconJohn for <p>You can't : your solution involves <code>xa2</code>, which doesn't appear in the definition of <code>R1</code> and <code>R2</code> ; <code>xa2</code> is an independent quantity.</p>
<p>May I suggest proofing your problem ?</p>
<p><strong>EDIT :</strong> After typo correction, it's clearer. And CAN be solved. Let's rewrite the problem a bit:</p>
<pre><code>xa1, xa2, xb1, xb2, a, b, R1, R2 = var('xa1, xa2, xb1, xb2, a, b, R1, R2')
Ua = xa1^a * xa2^b
Ub = xb1^a*xb2^b
MUa1=Ua.diff(xa1)
MUa2=Ua.diff(xa2)
MUb1=Ub.diff(xb1)
MUb2=Ub.diff(xb2)
MRSA=MUa1/MUa2
MRSB=MUb1/MUb2
Sol=solve([MRSA==MRSB],xa1)
</code></pre>
<p>Let's define R1 and R2 by <em>equations</em>, not assignments :</p>
<pre><code>E1=R1==xa1+xb1
E2=R2==xa2+xb2
</code></pre>
<p>Your solution is :</p>
<pre><code>sage: Sol
[xa1 == xa2*xb1/xb2]
</code></pre>
<p>We can solve <code>E1</code> and <code>E2</code> for <code>xa1</code> and <code>xa2</code> (thus getting tid of th<code>,</code>R2<code>and</code>xb2` :em) : </p>
<pre><code>sage: solve([E1,E2],[xa1,xa2])[0]
[xa1 == R1 - xb1, xa2 == R2 - xb2]
</code></pre>
<p>Let(' substitute that into your solution :</p>
<pre><code>sage: Sol[0].subs(solve([E1,E2],[xa1,xa2])[0])
R1 - xb1 == (R2 - xb2)*xb1/xb2
</code></pre>
<p>which gives us <code>xb1</code> as a function of <code>R1</code>, <code>R2</code> and <code>xb1</code> :</p>
<pre><code>sage: Sol[0].subs(solve([E1,E2],[xa1,xa2])[0]).solve(xb1)
[xb1 == R1*xb2/R2]
</code></pre>
<p>which if I understand you correctly,is the result you sought.</p>
<p>HTH,</p>
https://ask.sagemath.org/question/52480/deriving-a-contract-curve-in-sage/?comment=52508#post-id-52508How is it asymmetric?Thu, 16 Jul 2020 18:08:37 +0200https://ask.sagemath.org/question/52480/deriving-a-contract-curve-in-sage/?comment=52508#post-id-52508Comment by Emmanuel Charpentier for <p>You can't : your solution involves <code>xa2</code>, which doesn't appear in the definition of <code>R1</code> and <code>R2</code> ; <code>xa2</code> is an independent quantity.</p>
<p>May I suggest proofing your problem ?</p>
<p><strong>EDIT :</strong> After typo correction, it's clearer. And CAN be solved. Let's rewrite the problem a bit:</p>
<pre><code>xa1, xa2, xb1, xb2, a, b, R1, R2 = var('xa1, xa2, xb1, xb2, a, b, R1, R2')
Ua = xa1^a * xa2^b
Ub = xb1^a*xb2^b
MUa1=Ua.diff(xa1)
MUa2=Ua.diff(xa2)
MUb1=Ub.diff(xb1)
MUb2=Ub.diff(xb2)
MRSA=MUa1/MUa2
MRSB=MUb1/MUb2
Sol=solve([MRSA==MRSB],xa1)
</code></pre>
<p>Let's define R1 and R2 by <em>equations</em>, not assignments :</p>
<pre><code>E1=R1==xa1+xb1
E2=R2==xa2+xb2
</code></pre>
<p>Your solution is :</p>
<pre><code>sage: Sol
[xa1 == xa2*xb1/xb2]
</code></pre>
<p>We can solve <code>E1</code> and <code>E2</code> for <code>xa1</code> and <code>xa2</code> (thus getting tid of th<code>,</code>R2<code>and</code>xb2` :em) : </p>
<pre><code>sage: solve([E1,E2],[xa1,xa2])[0]
[xa1 == R1 - xb1, xa2 == R2 - xb2]
</code></pre>
<p>Let(' substitute that into your solution :</p>
<pre><code>sage: Sol[0].subs(solve([E1,E2],[xa1,xa2])[0])
R1 - xb1 == (R2 - xb2)*xb1/xb2
</code></pre>
<p>which gives us <code>xb1</code> as a function of <code>R1</code>, <code>R2</code> and <code>xb1</code> :</p>
<pre><code>sage: Sol[0].subs(solve([E1,E2],[xa1,xa2])[0]).solve(xb1)
[xb1 == R1*xb2/R2]
</code></pre>
<p>which if I understand you correctly,is the result you sought.</p>
<p>HTH,</p>
https://ask.sagemath.org/question/52480/deriving-a-contract-curve-in-sage/?comment=52509#post-id-52509You seem to describe two symmetric actors. I would expect either :
R1=xa1+xb1;
R2=xa2+xb2;
or
R1=xa1+xa2;
R2=xb1+xb2;Thu, 16 Jul 2020 18:35:26 +0200https://ask.sagemath.org/question/52480/deriving-a-contract-curve-in-sage/?comment=52509#post-id-52509Comment by EconJohn for <p>You can't : your solution involves <code>xa2</code>, which doesn't appear in the definition of <code>R1</code> and <code>R2</code> ; <code>xa2</code> is an independent quantity.</p>
<p>May I suggest proofing your problem ?</p>
<p><strong>EDIT :</strong> After typo correction, it's clearer. And CAN be solved. Let's rewrite the problem a bit:</p>
<pre><code>xa1, xa2, xb1, xb2, a, b, R1, R2 = var('xa1, xa2, xb1, xb2, a, b, R1, R2')
Ua = xa1^a * xa2^b
Ub = xb1^a*xb2^b
MUa1=Ua.diff(xa1)
MUa2=Ua.diff(xa2)
MUb1=Ub.diff(xb1)
MUb2=Ub.diff(xb2)
MRSA=MUa1/MUa2
MRSB=MUb1/MUb2
Sol=solve([MRSA==MRSB],xa1)
</code></pre>
<p>Let's define R1 and R2 by <em>equations</em>, not assignments :</p>
<pre><code>E1=R1==xa1+xb1
E2=R2==xa2+xb2
</code></pre>
<p>Your solution is :</p>
<pre><code>sage: Sol
[xa1 == xa2*xb1/xb2]
</code></pre>
<p>We can solve <code>E1</code> and <code>E2</code> for <code>xa1</code> and <code>xa2</code> (thus getting tid of th<code>,</code>R2<code>and</code>xb2` :em) : </p>
<pre><code>sage: solve([E1,E2],[xa1,xa2])[0]
[xa1 == R1 - xb1, xa2 == R2 - xb2]
</code></pre>
<p>Let(' substitute that into your solution :</p>
<pre><code>sage: Sol[0].subs(solve([E1,E2],[xa1,xa2])[0])
R1 - xb1 == (R2 - xb2)*xb1/xb2
</code></pre>
<p>which gives us <code>xb1</code> as a function of <code>R1</code>, <code>R2</code> and <code>xb1</code> :</p>
<pre><code>sage: Sol[0].subs(solve([E1,E2],[xa1,xa2])[0]).solve(xb1)
[xb1 == R1*xb2/R2]
</code></pre>
<p>which if I understand you correctly,is the result you sought.</p>
<p>HTH,</p>
https://ask.sagemath.org/question/52480/deriving-a-contract-curve-in-sage/?comment=52510#post-id-52510Oh I see the issue. It was right in front of me. EditingThu, 16 Jul 2020 18:37:38 +0200https://ask.sagemath.org/question/52480/deriving-a-contract-curve-in-sage/?comment=52510#post-id-52510