alpaqa
0.0.1
Nonconvex constrained optimization
Toggle main menu visibility
Main Page
Related Pages
Modules
Namespaces
Namespace List
Namespace Members
All
a
b
c
d
e
f
g
h
i
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
α
ε
λ
σ
Functions
a
c
d
e
g
h
i
l
m
n
o
p
r
s
u
w
Variables
a
b
c
d
e
f
g
h
i
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
α
ε
λ
σ
Typedefs
Enumerations
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
~
α
γ
δ
ε
θ
λ
ρ
σ
τ
φ
ψ
Functions
a
b
c
d
e
f
g
h
i
l
m
n
o
p
r
s
t
u
v
w
x
y
~
α
ρ
Variables
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
γ
δ
ε
θ
λ
ρ
σ
τ
φ
ψ
Typedefs
c
d
f
g
h
i
l
m
p
r
s
v
Enumerations
Enumerator
Files
File List
File Members
All
a
e
k
m
o
p
s
v
Functions
a
e
k
m
o
p
s
v
Variables
Typedefs
Macros
Examples
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Modules
Pages
examples
CasADi
Rosenbrock
codegen-rosenbrock.py
Go to the documentation of this file.
1
from
casadi
import
SX, Function, CodeGenerator, vertcat, jtimes, gradient
2
from
sys
import
argv
3
4
if
len(argv) < 2:
5
print(f
"Usage: {argv[0]} <name>"
)
6
exit(0)
7
8
x = SX.sym(
"x"
)
9
y = SX.sym(
"y"
)
10
z = SX.sym(
"z"
)
11
unknwns = vertcat(x, y, z)
12
13
w = SX.sym(
"w"
)
14
15
# Formulate the NLP
16
f = x**2 + 100*z**2
17
g = z + (1-x)**2 - y
18
19
cg = CodeGenerator(f
"{argv[1]}.c"
)
20
cg.add(Function(
"f"
, [unknwns],
21
[f],
22
[
"x"
], [
"f"
]))
23
cg.add(Function(
"grad_f"
, [unknwns],
24
[gradient(f, unknwns)],
25
[
"x"
], [
"grad_f"
]))
26
cg.add(Function(
"g"
, [unknwns],
27
[g],
28
[
"x"
], [
"g"
]))
29
cg.add(Function(
"grad_g"
, [unknwns, w],
30
[jtimes(g, unknwns, w,
True
)],
31
[
"x"
,
"w"
], [
"grad_g"
]))
32
cg.generate()
Generated by
1.9.2