#5612: docs for solving a system of linear equations symbolically using symbolic
matrices
----------------------------+-----------------------------------------------
 Reporter:  jason           |       Owner:  was       
     Type:  enhancement     |      Status:  new       
 Priority:  minor           |   Milestone:  sage-3.4.2
Component:  linear algebra  |    Keywords:            
----------------------------+-----------------------------------------------
 This should go into some docs somewhere.  Maybe under solve_right or in a
 primer?

 It's to solve the linear system a*x+b*y=3, c*x+d*y=5.

 {{{
 sage: var('a,b,c,d,x,y')
 (a, b, c, d, x, y)
 sage: A=matrix(2,[a,b,c,d]); A
 [a b]
 [c d]
 sage: result=vector([3,5]); result
 (3, 5)
 sage: soln=A.solve_right(result) # you could also do soln=A\result
 sage: soln
 (3/a - b*(5 - 3*c/a)/(a*(d - b*c/a)), (5 - 3*c/a)/(d - b*c/a))


 Now, checking our answers:


 sage: (a*x+b*y).subs(x=soln[0],y=soln[1]).simplify_full()
 3
 sage: (c*x+d*y).subs(x=soln[0],y=soln[1]).simplify_full()
 5


 Or just checking it with matrix multiplication:

 sage: A*soln
 (a*(3/a - b*(5 - 3*c/a)/(a*(d - b*c/a))) + b*(5 - 3*c/a)/(d - b*c/a),
 c*(3/a - b*(5 - 3*c/a)/(a*(d - b*c/a))) + (5 - 3*c/a)*d/(d - b*c/a))

 Let's simplify each entry by applying the "simplify_full" function to
 each entry:

 sage: (A*soln).apply_map(lambda x: x.simplify_full())
 (3, 5)
 }}}

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/5612>
Sage <http://sagemath.org/>
Sage - Open Source Mathematical Software: Building the Car Instead of 
Reinventing the Wheel

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to