Ask Your Question
0

how to properly substitute in a matrix?

asked 2011-06-23 13:12:36 +0100

roah gravatar image

updated 2011-06-23 13:15:25 +0100

kcrisman gravatar image

Let's consider a modified example from Sage reference manual

f(x,y)=x^2*y+y^2+y
solutions=solve(list(f.diff()),[x,y])
the_solution=solutions[2]
H=f.diff(2);  # Hessian matrix

How can i properly substitute the_solution into H?

I have tried:

H(x,y).subs(the_solution) - does not work.

This will work for H(x,y).subs(x==0)

H(x,y).subs_expr(*the_solution) - does not work.

This will work for f(x,y).subs_expr(*the_solution)

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2011-06-23 13:17:37 +0100

kcrisman gravatar image

updated 2011-06-23 13:18:42 +0100

Try this:

sage: solutions=solve(list(f.diff()),[x,y],solution_dict=True)
sage: solutions
[{y: 0, x: -I}, {y: 0, x: I}, {y: -1/2, x: 0}]
sage: H.subs(solutions[2])
[(x, y) |--> -1  (x, y) |--> 0]
[ (x, y) |--> 0  (x, y) |--> 2]

Or this:

sage: H(x,y).subs(solutions[2])
[-1  0]
[ 0  2]

I'm not sure exactly what output you are looking for.

The documentation for solve has some more information about this keyword.

edit flag offensive delete link more

Comments

Thanks, kcrisman! Maybe it is possible to include these lines into Sage Reference Manual? In the manual one enters the point manually... I don't know how to do this...

roah gravatar imageroah ( 2011-06-24 07:54:23 +0100 )edit

This is now http://trac.sagemath.org/sage_trac/ticket/11541. It would be a good beginner ticket to try :)

kcrisman gravatar imagekcrisman ( 2011-06-24 10:50:17 +0100 )edit
1

answered 2011-06-23 13:25:22 +0100

niles gravatar image

How about this?

sage: soln = [x.rhs() for x in the_solution]; soln
[0, -1/2]
sage: matrix([f(*soln) for f in H])
[-1  0]
[ 0  2]
edit flag offensive delete link more

Comments

Thanks, niles!

roah gravatar imageroah ( 2011-06-24 07:52:04 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-06-23 13:12:36 +0100

Seen: 958 times

Last updated: Jun 23 '11