ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 17 Nov 2021 11:48:34 +0100evaluation of hessian in some pointhttps://ask.sagemath.org/question/59762/evaluation-of-hessian-in-some-point/hi
this code works very well but i can not manage to make Sagemaths evaluate the matrix H in the critical points :
this is the two lines with f
from sage.manifolds.operators import *
E.<x,y> = EuclideanSpace()
f(x,y)=exp(-y^2)+x^4-x^2
F = E.scalar_field(f)
show("3) f",f)
show("grad f=",grad(F)[:])
H=f(x,y).hessian()
show("H=",H)
Cr= solve([grad(f)[0]==0,grad(f)[1]==0],[x,y])
show("points critiques : ",Cr)
#for critique in Cr:
# show(H(critique))#marche pas je comprend pas pourquoi
show("on voit les deux points-col et le max")
h(x,y,z)=f(x,y)-z
implicit_plot3d(h, (x, -4,4), (y, -4, 4), (z, -0.5, 5),color="blue",adaptive=True,mesh=True)Tue, 16 Nov 2021 14:21:54 +0100https://ask.sagemath.org/question/59762/evaluation-of-hessian-in-some-point/Answer by rburing for <p>hi
this code works very well but i can not manage to make Sagemaths evaluate the matrix H in the critical points :
this is the two lines with f</p>
<pre><code>from sage.manifolds.operators import *
E.<x,y> = EuclideanSpace()
f(x,y)=exp(-y^2)+x^4-x^2
F = E.scalar_field(f)
show("3) f",f)
show("grad f=",grad(F)[:])
H=f(x,y).hessian()
show("H=",H)
Cr= solve([grad(f)[0]==0,grad(f)[1]==0],[x,y])
show("points critiques : ",Cr)
#for critique in Cr:
# show(H(critique))#marche pas je comprend pas pourquoi
show("on voit les deux points-col et le max")
h(x,y,z)=f(x,y)-z
implicit_plot3d(h, (x, -4,4), (y, -4, 4), (z, -0.5, 5),color="blue",adaptive=True,mesh=True)
</code></pre>
https://ask.sagemath.org/question/59762/evaluation-of-hessian-in-some-point/?answer=59764#post-id-59764The return value of `solve` (when called in this way) is a list of lists of equations.
So, `H(critique)` is trying to evaluate `H` at a list of equations, which is not supported.
Instead, you can *substitute* a list of equations into `H`:
for critique in Cr:
show(H.subs(critique))
Alternatively you can pass the keyword argument `solution_dict=True` to the `solve` command, so that the return value becomes a list of dictionaries, each of which can be passed into `H`.Tue, 16 Nov 2021 15:45:30 +0100https://ask.sagemath.org/question/59762/evaluation-of-hessian-in-some-point/?answer=59764#post-id-59764Comment by slelievre for <p>The return value of <code>solve</code> (when called in this way) is a list of lists of equations.</p>
<p>So, <code>H(critique)</code> is trying to evaluate <code>H</code> at a list of equations, which is not supported.</p>
<p>Instead, you can <em>substitute</em> a list of equations into <code>H</code>:</p>
<pre><code>for critique in Cr:
show(H.subs(critique))
</code></pre>
<p>Alternatively you can pass the keyword argument <code>solution_dict=True</code> to the <code>solve</code> command, so that the return value becomes a list of dictionaries, each of which can be passed into <code>H</code>.</p>
https://ask.sagemath.org/question/59762/evaluation-of-hessian-in-some-point/?comment=59792#post-id-59792@ErWinz: you can accept the answer by clicking the "accept" button (the one with a check mark to the top left of the answer). This will mark the question as solved in the list of questions.Wed, 17 Nov 2021 11:48:34 +0100https://ask.sagemath.org/question/59762/evaluation-of-hessian-in-some-point/?comment=59792#post-id-59792Comment by ErWinz for <p>The return value of <code>solve</code> (when called in this way) is a list of lists of equations.</p>
<p>So, <code>H(critique)</code> is trying to evaluate <code>H</code> at a list of equations, which is not supported.</p>
<p>Instead, you can <em>substitute</em> a list of equations into <code>H</code>:</p>
<pre><code>for critique in Cr:
show(H.subs(critique))
</code></pre>
<p>Alternatively you can pass the keyword argument <code>solution_dict=True</code> to the <code>solve</code> command, so that the return value becomes a list of dictionaries, each of which can be passed into <code>H</code>.</p>
https://ask.sagemath.org/question/59762/evaluation-of-hessian-in-some-point/?comment=59781#post-id-59781wonderful thanks very much !Wed, 17 Nov 2021 04:38:51 +0100https://ask.sagemath.org/question/59762/evaluation-of-hessian-in-some-point/?comment=59781#post-id-59781