import casadi as cs
import opengen as og
def rk4_explicit(fun,x,u,t_step):
k1 = fun(x, u)
k2 = fun(x + t_step*k1/2, u)
k3 = fun(x + t_step*k2/2, u)
k4 = fun(x + t_step*k3, u)
return x + (t_step/6)*(k1 + 2*k2 + 2*k3 + k4);
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 Function, MX, symvar, veccat | |
def lin(expr): | |
# Get list of symbols s present in expression expr(s). | |
s = symvar(expr) | |
# Convert list into a column-vector of symbols x. | |
# If the size of the symbols present in the expression expr is not 1x1, vertcat will not be able to create a column-vector of symbols. | |
# That's why we use veccat instead of vertcat | |
x = veccat(*s) | |
# Define variable x0 with same sparsity as x. |
To install the Matlab2Tikz library, just follow the installation instructions in the Matlab2Tikz GitHub.
The easiest way to use the Matlab2Tikz library is with the custom function save_figure
.
Just create an empty script, copy the following code, paste it in the script, and save it as save_figure.m
. This script must be placed in the working directory of MATLAB, or you can include it into the MATLAB path.
function save_figure(fig_handle, fig_name, ppi)
%SAVE_FIGURE Saves any matlab figure in FIG, EPS, PNG or TIKZ format