Ask Your Question
0

How can I get back an expression for free variables in solve function.

asked 2017-11-06 04:50:27 -0600

I have a number of linear equations on some symbols A,B,C,D,E,F,G. When I solve them in Sagemath, I get some free variables in the solution.

$A,B,C,D,E,F,G=var('A,B,C,D,E,F,G')$

$eqns=[A+B==0,C+D+E==0,F+G==0,A+E-F==0]$

$solution=solve(eqns,A,B,C,D,E,F,G)$

Sage gives the following solution: $[[A == r1, B == -r1, C == r1 - r2 - r3, D == r3, E == -r1 + r2, F == r2, G == -r2]]$

Now I can ask Sage to give me an expression of any combination of the symbols, for example: $(A+C).subs(solution)$, then I get $2*r1 - r2 - r3$. For my purpose I would now like to have an expression for any of the free variables. If I assign $r1=var('r1')$ and ask Sage $s1.subs(solution)$ I get back $r1$ again. But I would lik to get back an expression in terms of $A,B,C,D,E,F,G$. Any suggestions on how to do this?

edit retag flag offensive close merge delete

Comments

I am not sure to fully understand your question, but I also think that it is not well-defined. In your example, you want to express r1 in terms of the variables A to G. But you can write r1 in several manners: r1 = A works, as well as r1 = -B or r1 = C + D - F, etc. So it is not clear to me which answer you are looking for.

B r u n o gravatar imageB r u n o ( 2017-11-06 07:29:14 -0600 )edit

Yes, I can see that. And I would just like to have one of these solutions, but probably this is not possible. The reason I am looking for this is that I have a C-vectorspace defined over some symbols (in this case, just a random example, the symbols A,B,C,D,E,F,G) and I want to quotient this space by a space spanned by some linear combinations of these symbols (in this case A+B==0, etc). When I did this by hand, I used the solved function, and could then see that a basis for my quotient space would be <a,-g,d>. To implement this process, I thought of also using the solve function, but it needs to give me an expression for the free variables. But probably this is not really the right approach :)

TheBeiram gravatar imageTheBeiram ( 2017-11-06 07:38:21 -0600 )edit

You may use the VectorSpace constructions (I do not know this well...) :

sage: v = VectorSpace(CC, 7)
sage: A,B,C,D,E,F,G = v.basis()
sage: s = v.subspace([A+B, C+D+E, F+G, A+E-F])
sage: q = v.quotient(s)
sage: [q.lift(x) for x in q.basis()]

    [(1.00000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000),
 (0.000000000000000, 0.000000000000000, 1.00000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000),
 (0.000000000000000, 0.000000000000000, 0.000000000000000, 1.00000000000000, 0.000000000000000, 0.000000000000000, 0.000000000000000)]

See more in the doc.

B r u n o gravatar imageB r u n o ( 2017-11-06 08:12:28 -0600 )edit

Yes that sounds nice. Any idea how to get rid of the many zeros?

TheBeiram gravatar imageTheBeiram ( 2017-11-06 09:36:26 -0600 )edit

Do you mean the trailing zeroes in each value? Using the field CC, this is the standard display. There has been an attempt to make this standard display customizable but it never converged. Two options for you if you want a different way of displaying the results: Either you work over another field, such as CDF (Complex Double Field) or CIF (Complex Interval Field) which have different behaviors, including a different display. Or you print yourself the result, using format. For instance, if you have the element x = 1.00000000000000, print("{:.4}".format(x)) prints x as a string of length 4, that is 1.00.

B r u n o gravatar imageB r u n o ( 2017-11-06 10:04:10 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-11-06 10:49:28 -0600

ndomes gravatar image

Are you looking for something like this ?

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

2 followers

Stats

Asked: 2017-11-06 04:29:40 -0600

Seen: 38 times

Last updated: Nov 06