misc.calculus

Package misc :: Module calculus |
[hide private]
[frames] | no frames]

# Source Code for Module misc.calculus

     1  from sympy import *
     2  from scipy import *
     3  import extern.qz
     4
     5 -def second_order_taylorisation(expr,shocks,covariances):
     6      h = hessian(expr,shocks)
     7      print(h)
     8      resp = expr
     9      for i in range(covariances.shape[0]):
    10          for j in range(covariances.shape[1]):
    11              resp = resp + h[i,j] * covariances[i,j] / 2
    12      for s in shocks:
    13          resp = resp.subs(s,0)
    14      return(resp)
    15
    16 -def construct_4_blocks_matrix(blocks):
    17      '''construct block matrix line by line
    18      input : [[A1,A2],[A3,A4]]
    19      '''
    20      A1 = blocks[0][0]
    21      A2 = blocks[0][1]
    22      A3 = blocks[1][0]
    23      A4 = blocks[1][1]
    24
    25      [p1,q1] = (blocks[0][0]).shape
    26      [p2,q2] = (blocks[0][1]).shape
    27      [p3,q3] = (blocks[1][0]).shape
    28      [p4,q4] = (blocks[1][1]).shape
    29      if p1<>p2 or p3<>p4 or q1<>q3 or q2<>q4:
    30          raise('dimension mismatch')
    31      m = zeros((p1+p3,q1+q2))
    32      print(m)
    33      print('A1',A1)
    34      print(m[0:p1,0:q1])
    35      m[0:p1,0:q1] = A1
    36      m[0:p1,q1:(q1+q2)] = A2
    37      m[p1:p1+p3,0:q1] = A3
    38      m[p1:p1+p3,q1:(q1+q2)] = A4
    39
    40      return(m)
    41