Ok I am solving the eigenvalues and vectors for a coupled DE. All I need to know is how to extract the solutions to the solve function. It turns out that there are four solutions. I would like to find a way to extract each of them instead of the cut and paste method. I tried the usual python index soln[0:1] also with the flatten command but that did not work.
--
To post to this group, send email to sage-s...@googlegroups.com
To unsubscribe from this group, send email to sage-support...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-support
URL: http://www.sagemath.org
I'm not an expert (newish sage user) but I think you want to use the solve function with solution_dict=True. This will give your solutions as a dictionary which can then be indexed in the normal way.More about that on this page:
Vince
On 6 March 2012 18:36, Eric Kangas <eric.c...@gmail.com> wrote:
Ok I am solving the eigenvalues and vectors for a coupled DE. All I need to know is how to extract the solutions to the solve function. It turns out that there are four solutions. I would like to find a way to extract each of them instead of the cut and paste method. I tried the usual python index soln[0:1] also with the flatten command but that did not work.
--
To post to this group, send email to sage-s...@googlegroups.com
To unsubscribe from this group, send email to sage-support+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-support
URL: http://www.sagemath.org
sage: var("x y")
(x, y)
sage: sols = solve([x^2-4==0, y^2-9==0], x, y, solution_dict=True)
sage: sols
[{y: -3, x: -2}, {y: -3, x: 2}, {y: 3, x: -2}, {y: 3, x: 2}]
This is just like any other list -- the fact the elements happen to be
dictionaries doesn't change anything -- and can be looped over and
indexed. For example:
sage: sols[0]
{y: -3, x: -2}
sage: sols[0][x]
-2
sage: sols[0][y]
-3
sage: sols[1][x]
2
sage: sols[1][y]
-3
sage: sum(sol[x]+sol[y] for sol in sols)
0
etc.
Doug
a,l,x,y,u,v,xdot,ydot,udot,vdot = var('a,l,x,y,u,v,xdot,ydot,udot,vdot', domain = RR)
i = var('i', domain = QQ)
xdot = x;
ydot = y;
udot = u^2+v;
vdot = v^2+u;
N = matrix([(diff(xdot,x)-l,diff(xdot,y),diff(xdot,u),diff(xdot,v)),(diff(ydot,x),diff(ydot,y)-l,diff(ydot,u),diff(ydot,v)),(diff(udot,x),diff(udot,y),diff(udot,u)-l,diff(udot,v)),(diff(vdot,x),diff(vdot,y),diff(vdot,u),diff(vdot,v)-l)])
dN = N[0,0]*(N[1,1]*(N[2,2]*N[3,3]-N[2,3]*N[3,2]) + N[1,2]*(N[1,2]*N[3,3]-N[3,2]*N[1,3]) + N[1,3]*(N[1,2]*N[2,3]-N[2,2]*N[1,3])) + N[1,0]*(N[0,1]*(N[2,2]*N[3,3]-N[3,2]*N[2,3]) + N[2,1]*(N[0,2]*N[3,3]-N[3,2]*N[0,3]) + N[3,1]*(N[0,2]*N[2,3]-N[2,2]*N[0,3])) + N[2,0]*(N[1,0]*(N[1,2]*N[3,3]-N[3,2]*N[1,3]) + N[1,1]*(N[0,2]*N[3,3]-N[3,2]*N[0,3]) + N[1,3]*(N[0,2]*N[1,3]-N[1,2]*N[0,3])) + N[3,0]*(N[0,1]*(N[1,2]*N[2,3]-N[2,2]*N[1,3]) + N[1,1]*(N[0,2]*N[2,3]-N[2,2]*N[0,3]) + N[2,1]*(N[0,2]*N[1,3]-N[1,2]*N[0,3]))
soln = solve([dN == 0], l);
sol0(u,v) = soln[0];
sol1(u,v) = soln[1];
sol2(u,v) = soln[2];