Ask Your Question
7

Using the solution of equation

asked 2010-10-18 13:25:45 +0100

czsan gravatar image

updated 2011-04-28 15:57:38 +0100

Kelvin Li gravatar image

How can I use after solve(eq) the result? For example, the result for this simple linear system

[x + 2*y + 4*z - 1]
[      x + 4*z - 5]
[    3*x + 6*z - 6]

is

[[x == -1, y == -2, z == (3/2)]]

How can I use x,y,z in an expression, say x^2+y^2+z^2 ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
9

answered 2010-10-18 14:22:08 +0100

Mike Hansen gravatar image

The easiest way is to pass solution_dict=True to the solve command.

sage: var('x,y,z')
(x, y, z)
sage: eqs = [x + 2*y + 4*z - 1 == 0, x + 4*z - 5 == 0,  3*x + 6*z - 6]
sage: solve(eqs, (x,y,z))
[[x == -1, y == -2, z == (3/2)]]
sage: sols = solve(eqs, (x,y,z), solution_dict=True); sols
[{z: 3/2, y: -2, x: -1}]

Then, you can pass that dictionary into the subs method of your expression. For example,

sage: f = x^2 + y^2 + z^2
sage: [f.subs(sol) for sol in sols]
[29/4]
edit flag offensive delete link more

Comments

Thank you, it seems to good.

czsan gravatar imageczsan ( 2010-10-18 17:07:15 +0100 )edit

Your Answer

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

Add Answer

Question Tools

2 followers

Stats

Asked: 2010-10-18 13:25:45 +0100

Seen: 1,518 times

Last updated: Oct 18 '10