Message Boards Message Boards

0
|
6195 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

[?] Calculate the Hessian?

Posted 7 years ago

I have to calculate the gradient and hessian of functions with a lot of paramteres and therefore I started using Mathematica. Calculating the gradient works fine, but Mathematica won't calculate the hessian, it just displays Hessian[function[...]] as output.

What am I doing wrong?

In[18]:= L[P[1],Q[1],V[1]]=a[1]+b[1]*P[1]+c[1]*P[1]^2+l[11]*(P[1]-V[1]*(V[5]*(G[15]*Cos[t[1]-t[5]]+B[15]*Sin[t[1]-t[5]])+V[1]*G[11]))+l[12]*(Q[1]-V[1]*(V[5]*(G[15]*Sin[t[1]-t[2]]-B[15]*Cos[t[1]-t[2]])-V[1]*B[11]))+z[11]*(0.9-V[1])+z[12]*(V[1]-1.1)
Grad[L[P[1],Q[1],V[1]],{P[1],Q[1],V[1]}]
Hessian[L[P[1],Q[1],V[1]],{P[1],Q[1],V[1]}]
Jacobian[{b[1] + l[11] + 2*c[1]*P[1], l[12], 
  l[12]*(2*B[11]*V[1] - ((-B[15])*Cos[t[1] - t[2]] + G[15]*Sin[t[1] - t[2]])*
      V[5]) + l[11]*(-2*G[11]*V[1] - (Cos[t[1] - t[5]]*G[15] + 
       B[15]*Sin[t[1] - t[5]])*V[5]) - z[11] + z[12]},{P[1],Q[1],V[1]}]

Out[18]= a[1]+b[1] P[1]+c[1] P[1]^2+l[12] (Q[1]-V[1] (-B[11] V[1]+(-B[15] Cos[t[1]-t[2]]+G[15] Sin[t[1]-t[2]]) V[5]))+l[11] (P[1]-V[1] (G[11] V[1]+(Cos[t[1]-t[5]] G[15]+B[15] Sin[t[1]-t[5]]) V[5]))+(0.9-V[1]) z[11]+(-1.1+V[1]) z[12]

Out[19]= {b[1]+l[11]+2 c[1] P[1],l[12],l[12] (2 B[11] V[1]-(-B[15] Cos[t[1]-t[2]]+G[15] Sin[t[1]-t[2]]) V[5])+l[11] (-2 G[11] V[1]-(Cos[t[1]-t[5]] G[15]+B[15] Sin[t[1]-t[5]]) V[5])-z[11]+z[12]}

Out[20]= Hessian[a[1]+b[1] P[1]+c[1] P[1]^2+l[12] (Q[1]-V[1] (-B[11] V[1]+(-B[15] Cos[t[1]-t[2]]+G[15] Sin[t[1]-t[2]]) V[5]))+l[11] (P[1]-V[1] (G[11] V[1]+(Cos[t[1]-t[5]] G[15]+B[15] Sin[t[1]-t[5]]) V[5]))+(0.9-V[1]) z[11]+(-1.1+V[1]) z[12],{P[1],Q[1],V[1]}]

Out[21]= Jacobian[{b[1]+l[11]+2 c[1] P[1],l[12],l[12] (2 B[11] V[1]-(-B[15] Cos[t[1]-t[2]]+G[15] Sin[t[1]-t[2]]) V[5])+l[11] (-2 G[11] V[1]-(Cos[t[1]-t[5]] G[15]+B[15] Sin[t[1]-t[5]]) V[5])-z[11]+z[12]},{P[1],Q[1],V[1]}]
POSTED BY: Jakob Weiler
2 Replies
Posted 7 years ago

Okay, thank you very much! Helped me alot!

POSTED BY: Jakob Weiler
Posted 7 years ago

Hello Jakob,

Hessian and Jacobian are not defined functions in Mathematica, Try this:

?? Grad
?? Hessian

But you can get the results in this way:

eq1 = L[P[1], Q[1], V[1]] = 
  a[1] + b[1]*P[1] + c[1]*P[1]^2 + 
   l[11]*(P[1] - 
      V[1]*(V[5]*(G[15]*Cos[t[1] - t[5]] + B[15]*Sin[t[1] - t[5]]) + 
         V[1]*G[11])) + 
   l[12]*(Q[1] - 
      V[1]*(V[5]*(G[15]*Sin[t[1] - t[2]] - B[15]*Cos[t[1] - t[2]]) - 
         V[1]*B[11])) + z[11]*(0.9 - V[1]) + z[12]*(V[1] - 1.1)

hessian = D[eq1, {{P[1], Q[1], V[1]}, 2}]
jacobian = 
 D[{b[1] + l[11] + 2 c[1] P[1], l[12], 
   l[12] (2 B[11] V[
         1] - (-B[15] Cos[t[1] - t[2]] + G[15] Sin[t[1] - t[2]]) V[
         5]) + l[11] (-2 G[11] V[
         1] - (Cos[t[1] - t[5]] G[15] + B[15] Sin[t[1] - t[5]]) V[
         5]) - z[11] + z[12]}, {{P[1], Q[1], V[1]}, 2}]
POSTED BY: Michael Helmle
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract