On Mar 25, 10:21 am, Jason Grout <jason-s...@creativetrax.com> wrote:
> Drini wrote:
>
> Here it is using linear algebra:
>
> 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)
>
> This example probably ought to go into some documentation somewhere...
>
> Jason

I will try, I just realized how silly I was thinking "result" vector
had to be numeric

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to