First time here? Check out the FAQ!

Ask Your Question
0

how to properly substitute in a matrix?

asked 13 years ago

roah gravatar image

updated 13 years ago

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)

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
1

answered 13 years ago

kcrisman gravatar image

updated 13 years ago

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.

Preview: (hide)
link

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 ( 13 years ago )

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

kcrisman gravatar imagekcrisman ( 13 years ago )
1

answered 13 years ago

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]
Preview: (hide)
link

Comments

Thanks, niles!

roah gravatar imageroah ( 13 years ago )

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: 13 years ago

Seen: 1,027 times

Last updated: Jun 23 '11