SX/sparsity_jac.py

This example looks at the sparsity_jac method

View output (PDF) | source (python)

See also
casadi::SXfunction::sparsity_jac();
1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 from casadi import *
28 from numpy import *
29 import casadi as c
30 from pylab import spy, show
31 
32 
33 
34 x = SX.sym("x",40)
35 y = x[:-2]-2*x[1:-1]+x[2:]
36 
37 
38 
39 print(y[:5])
40 
41 
42 
43 f = Function("f", [x],[y])
44 
45 
46 
47 spy(f.sparsity_jac(0, 0))
48 
49 show()