Function/expand.py

This example looks at the expand method

View output (PDF) | source (python)

See also
Function expand() const
Expand a function to SX.
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 import casadi as c
29 
30 
31 
32 x = MX.sym("x",2,2)
33 y = MX.sym("y",2,1)
34 
35 z = mtimes(x,y)
36 
37 
38 
39 f = Function("f", [x,y],[z])
40 
41 
42 
43 fSX = f.expand('fSX')
44 
45 print("Expanded expression = ", fSX.str(True))
46 
47 
48 
49 
50 
51 
52 
53 linear_solver = Linsol("linear_solver", "csparse", x.sparsity())
54 g = linear_solver.solve(x, y)
55 G = Function("G", [x,y], [g])
56 
57 
58 
59 try:
60  G.expand('G_sx')
61 except Exception as e:
62  print(e)