This example looks at a use for the NLP solvers
View output (PDF) | source (python)
- See also
40 nlp = {
'x':x,
'f':(x-1)**2}
42 solver =
nlpsol(
'solver',
'ipopt', nlp)
43 sol = solver(lbx=-10, ubx=10)
48 assert(abs(sol[
'x']-1)<1e-9)
65 nlp = {
'x':x,
'f':mtimes((x-1).T,x-1),
'g':vertcat(x[1]+x[2],x[0])}
67 solver =
nlpsol(
'solver',
'ipopt', nlp)
68 sol = solver(lbx=-10, ubx=10, lbg=[0,2], ubg=[1,2])
76 for (i,e)
in zip(list(range(n)),[2,0.5,0.5,1,1]):
77 assert(abs(sol[
'x'][i]-e)<1e-7)
90 nlp={
'x':x,
'p':a,
'f':(x-a)**2}
92 solver =
nlpsol(
'solver',
'ipopt', nlp)
93 sol = solver(lbx=-10, ubx=10, p=a_)
98 assert(abs(sol[
'x']-a_)<1e-9)
102 sol = solver(lbx=-10, ubx=10, p=2*a_)
107 assert(abs(sol[
'x']-2*a_)<1e-9)
CASADI_EXPORT Function nlpsol(const std::string &name, const std::string &solver, const SXDict &nlp, const Dict &opts=Dict())