Building on an example I've found here, I am trying to create a function from a diagonal matrix that was created using sumpy.diag
myM = Matrix([
[x1, 4, 4],
[4, x2, 4],
[4, 4, x3]])
Where this was created using this routine for example:
import sympy as sp
import numpy as np
x1 = sp.Symbol('x1')
x2 = sp.Symbol('x2')
x3 = sp.Symbol('x3')
X = sp.Matrix([x1, x2, x3])
myM = 4 * sp.ones(3, 3)
sp.diag(*X) + myM - sp.diag(*np.diag(myM))
now I will like to create a function, using lambdify
of ufuncify
, that takes a numpy.array
or length 3 (like np.array([0.1,0.2,0.3])
)as an input, and gives the output as a matrix according to myM
myM = Matrix([
[0.1, 4, 4],
[4, 0.2, 4],
[4, 4, 0.3]])
Eventually I need to create a Jacobian matrix symbolically using this method: And as the functional form may change during the calculation, then having the Jacobian calculated symbolically would be very useful.