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, 10 May 2021 14:00:36 +0200How can I isolate and print termhttps://ask.sagemath.org/question/57044/how-can-i-isolate-and-print-term/ Given the following:
a = var('a')
b = var('b')
c0 = var('c0')
c1 = var('c1')
eq1 = a==exp(b)
eq2 = b==4*c0+2*c1
solve([eq1, eq2], a, b, c0, c1, solution_dict=True)
[{a: e^r5, b: r5, c0: r6, c1: 1/2*r5 - 2*r6}]
I'd like extract `a` and have something similar to what I would have if I did: `view(a==exp(4*c0+2*c1))`.
Sun, 09 May 2021 22:19:51 +0200https://ask.sagemath.org/question/57044/how-can-i-isolate-and-print-term/Comment by kuon for <p>Given the following:</p>
<pre><code>a = var('a')
b = var('b')
c0 = var('c0')
c1 = var('c1')
eq1 = a==exp(b)
eq2 = b==4*c0+2*c1
solve([eq1, eq2], a, b, c0, c1, solution_dict=True)
[{a: e^r5, b: r5, c0: r6, c1: 1/2*r5 - 2*r6}]
</code></pre>
<p>I'd like extract <code>a</code> and have something similar to what I would have if I did: <code>view(a==exp(4*c0+2*c1))</code>.</p>
https://ask.sagemath.org/question/57044/how-can-i-isolate-and-print-term/?comment=57056#post-id-57056With the accepted answer, I can do `view(a == sols[0][a])` which is what I meant.Mon, 10 May 2021 14:00:36 +0200https://ask.sagemath.org/question/57044/how-can-i-isolate-and-print-term/?comment=57056#post-id-57056Comment by Emmanuel Charpentier for <p>Given the following:</p>
<pre><code>a = var('a')
b = var('b')
c0 = var('c0')
c1 = var('c1')
eq1 = a==exp(b)
eq2 = b==4*c0+2*c1
solve([eq1, eq2], a, b, c0, c1, solution_dict=True)
[{a: e^r5, b: r5, c0: r6, c1: 1/2*r5 - 2*r6}]
</code></pre>
<p>I'd like extract <code>a</code> and have something similar to what I would have if I did: <code>view(a==exp(4*c0+2*c1))</code>.</p>
https://ask.sagemath.org/question/57044/how-can-i-isolate-and-print-term/?comment=57050#post-id-57050> something similar to what I would have if I did: `view(a==exp(4*c0+2*c1))`.
What is this supposed to mean ? Could you give us something similar to an example of what you expect ?Mon, 10 May 2021 07:56:13 +0200https://ask.sagemath.org/question/57044/how-can-i-isolate-and-print-term/?comment=57050#post-id-57050Answer by rburing for <p>Given the following:</p>
<pre><code>a = var('a')
b = var('b')
c0 = var('c0')
c1 = var('c1')
eq1 = a==exp(b)
eq2 = b==4*c0+2*c1
solve([eq1, eq2], a, b, c0, c1, solution_dict=True)
[{a: e^r5, b: r5, c0: r6, c1: 1/2*r5 - 2*r6}]
</code></pre>
<p>I'd like extract <code>a</code> and have something similar to what I would have if I did: <code>view(a==exp(4*c0+2*c1))</code>.</p>
https://ask.sagemath.org/question/57044/how-can-i-isolate-and-print-term/?answer=57051#post-id-57051You want the equations to hold for *all* values of `c0`, `c1`, so you can omit them as variables to solve for:
sage: solve([eq1, eq2], a, b)
[[a == e^(4*c0 + 2*c1), b == 4*c0 + 2*c1]]
To extract the solution for `a` in particular, you can do e.g.
sage: sols = solve([eq1, eq2], a, b, solution_dict=True); sols
[{a: e^(4*c0 + 2*c1), b: 4*c0 + 2*c1}]
sage: a == sols[0][a]
a == e^(4*c0 + 2*c1)Mon, 10 May 2021 09:06:22 +0200https://ask.sagemath.org/question/57044/how-can-i-isolate-and-print-term/?answer=57051#post-id-57051