About the solve function

41 views
Skip to first unread message

Eric Kangas

unread,
Mar 6, 2012, 1:36:59 PM3/6/12
to sage-s...@googlegroups.com
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.

Vincent Knight

unread,
Mar 6, 2012, 1:55:08 PM3/6/12
to sage-s...@googlegroups.com
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...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-support
URL: http://www.sagemath.org



--
Dr Vincent Knight
Cardiff School of Mathematics
Senghennydd Road,
Cardiff
CF24 4AG
(+44) 29 2087 5548
Skype: drvinceknight

Eric Kangas

unread,
Mar 9, 2012, 1:34:54 PM3/9/12
to sage-s...@googlegroups.com
I tried using the solution_dict option and I was still not able to index each solution from the solve function.


On Tuesday, March 6, 2012 10:55:08 AM UTC-8, Vincent Knight wrote:
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

D. S. McNeil

unread,
Mar 9, 2012, 3:18:40 PM3/9/12
to sage-s...@googlegroups.com
You're probably getting a list of dictionaries:

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

Eric Kangas

unread,
Mar 15, 2012, 1:42:57 PM3/15/12
to sage-s...@googlegroups.com
I am able to manipulate the functions, but I am unable to plot them.

Here is the code:

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];

Reply all
Reply to author
Forward
0 new messages