Skip to content

Instantly share code, notes, and snippets.

@jgillis
Created May 24, 2013 07:49
Show Gist options
  • Save jgillis/5641954 to your computer and use it in GitHub Desktop.
Save jgillis/5641954 to your computer and use it in GitHub Desktop.
casadi multiple sensitivities
from casadi import *
x = msym("x",2)
y = msym("y",2,2)
f = MXFunction([x,y],[mul(y,x),y])
f.setOption("number_of_fwd_dir",2)
f.init()
f.input(0).set(DMatrix([1.1,1.3]))
f.input(1).set(DMatrix([[0.7,1.5],[2.1,0.9]]))
f.setFwdSeed(DMatrix([1.1,1.3]),0,0)
f.setFwdSeed(DMatrix([0.7,.3]),0,1)
f.evaluate(1,0)
J_ = f.output(1)
for d in range(2):
seed = f.fwdSeed(0,d)
sens = f.fwdSens(0,d)
print sens,mul(J_,seed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment