This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from casadi import * | |
x = MX.sym('x') | |
y = MX.sym('y') | |
p = MX.sym('p') | |
nlp = {"x":vertcat(x,y),"p":p,"f":(x-2)**4+(y-3)**2} | |
solver = nlpsol('solver','ipopt',nlp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# This file is part of rockit. | |
# | |
# rockit -- Rapid Optimal Control Kit | |
# Copyright (C) 2019 MECO, KU Leuven. All rights reserved. | |
# | |
# Rockit is free software; you can redistribute it and/or | |
# modify it under the terms of the GNU Lesser General Public | |
# License as published by the Free Software Foundation; either | |
# version 3 of the License, or (at your option) any later version. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import casadi.* | |
x = MX.sym('x'); | |
y = MX.sym('y'); | |
xy = [x;y]; | |
p = MX.sym('p'); | |
nlp = struct; | |
nlp.x = xy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from casadi import SX, vertcat, inf | |
# Declare variables | |
x = SX.sym("x") | |
y = SX.sym("y") | |
z = SX.sym("z") | |
# Formulate the NLP | |
f = x**2 + 100*z**2 | |
g = z + (1-x)**2 - y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from ctypes import * | |
class CasadiSparsity: | |
""" | |
Compressed Columun storage sparsity pattern | |
""" | |
def __init__(self,sp): | |
self.n_row = sp[0] | |
self.n_col = sp[1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from casadi import * | |
x=SX.sym("x") | |
y=SX.sym("y") | |
f = (1-x)**2+100*(y-x**2)**2 | |
nlp={'x':vertcat(x,y), 'f':f,'g':x+y} | |
fcn = Function('f', [x, y], [f]) | |
callback_inputs = dict() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import casadi.* | |
opti = Opti(); | |
x = opti.variable(2); | |
fx = sin(x)-[2;0.3]; | |
opti.minimize(sumsqr(fx)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import casadi.* | |
% Per https://en.wikipedia.org/wiki/Numerical_integration | |
% F(x) = int_a^x f(u) du | |
% <-> dF(x)/dx = f(x), F(a)=0 | |
f = @(x) x.^5; | |
interv = [1.1 2.3]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from casadi import * | |
opti = Opti() | |
N = 5 | |
degree = 3 | |
grid = np.linspace(0, 6, N) | |
# knots ~ grid but with multiplicity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
close all | |
% casadi.interpolant creates 'knots' and 'coefficients' out of data and passes it on to casadi.Function.bspline | |
% Here, we supply knots and coefficients directly to casadi.Function.bspline | |
%% Example 1: discontinuous example, just to make clear the interpretation | |
% of the pp = piecewise polynomial form clear | |
% 4 intervals: 0-1, 1-2, 2-4, 4-6 |