Processing math: 100%
Ask Your Question
1

How to simplify `solve` result (ri variables)?

asked 8 years ago

drzee gravatar image

I want to solve a system of linear equations (more variables than equations):

var('a, b, c')
eqn = [a+b+c==4, a+b-c==5]
s = solve(eqn, a, b, c); s

The result is shown like this:

[[a=r39+92,b=r39,c=(12)]]

But I would like to have a simplified representation, i.e., where r39 in the first equation is replaced by b. Alternatively, is there a way to reset the counter of the ri variables? Each time I evaluate the code above, the counter is incremented.

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
0

answered 8 years ago

tmonteil gravatar image

Note that your case is very particular since in general, there is no reason why the free parameters coincide with some of the variables.

It is probably not be what you are looking for, but here is a generic way to deal with systems of linear equations:

sage: M = matrix(QQ,[[1,1,1],[1,1,-1]])
sage: M
[ 1  1  1]
[ 1  1 -1]

sage: part_sol = M.solve_right(vector([4,5])) ; part_sol
(9/2, 0, -1/2)

sage: kern = M.right_kernel() ; kern
Vector space of degree 3 and dimension 1 over Rational Field
Basis matrix:
[ 1 -1  0]
sage: kernel_basis = kern.basis()
[
(1, -1, 0)
]

Then the solution set is the sum of part_sol with any linear combination of the elements of the basis of the kernel, in your case it is : (9/2, 0, -1/2) + t*(1, -1, 0) for any t in your field (i chosed Q).

Preview: (hide)
link
1

answered 8 years ago

dan_fulea gravatar image

Restarting the session also resets the rj Expression instances. The code cannot produce the solution in the form b=b instead of b=r39, and if it would, then i would like the other version.

If we know which variables are relevant, we could try to solve then only with respect to those variables. For instance:

sage: var('a,b,c');
sage: solve( [ a+b+c == 4, a+b-c == 5], [a, b] )
[]
sage: solve( [ a+b+c == 4, a+b-c == 5], [a, c] )
[[a == -b + 9/2, c == (-1/2)]]
sage: solve( [ a+b+c == 4, a+b-c == 5], [b, c] )
[[b == -a + 9/2, c == (-1/2)]]

Or the extended matrix of the system may give the necessary information.

A more fancy way to get the "relevant equations" would be to use the ideal generated by the equations, for instance:

sage: R.<a,b,c> = PolynomialRing( QQ )
sage: R
Multivariate Polynomial Ring in a, b, c over Rational Field
sage: J = R.ideal( [ a+b+c - 4, a+b-c -5 ] )
sage: J.groebner_basis()
[a + b - 9/2, c + 1/2]

and the above result can be digested as follows: The given equations a+b+c4=0, a+bc5=0 are equivalent with the two (simpler) equations a+b9/2=0, c+1/2=0.

Preview: (hide)
link

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 8 years ago

Seen: 878 times

Last updated: Mar 15 '17