Ask Your Question

How can I isolate and print term

asked 2021-05-09 22:19:51 +0200

kuon gravatar image

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 flag offensive 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 ?

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 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.

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

1 Answer

Sort by ยป oldest newest most voted

answered 2021-05-10 09:06:22 +0200

rburing gravatar image

updated 2021-05-10 09:06:53 +0200

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)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2021-05-09 22:19:51 +0200

Seen: 260 times

Last updated: May 10 '21