# 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)).

edit retag close merge delete

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 ?

( 2021-05-10 07:56:13 +0200 )edit

With the accepted answer, I can do view(a == sols[0][a]) which is what I meant.

( 2021-05-10 14:00:36 +0200 )edit

Sort by ยป oldest newest most voted

You 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)

more