Using the solution of equation

i like this post (click again to cancel)
5
i dont like this post (click again to cancel)

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 ?

asked Oct 18 '10

czsan gravatar image czsan
133 1 5 16

updated Apr 28 '11

Kelvin Li gravatar image Kelvin Li
423 9 16
i like this answer (click again to cancel)
6
i dont like this answer (click again to cancel)

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]
link

posted Oct 18 '10

Mike Hansen gravatar image Mike Hansen flag of United States
3675 19 43 81
Thank you, it seems to good. czsan (Oct 18 '10)

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
[hide preview]

Question tools

1 follower

Tags:

Stats:

Asked: Oct 18 '10

Seen: 163 times

Last updated: Oct 18 '10

powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.