Giter Site home page Giter Site logo

Comments (4)

jgillis avatar jgillis commented on June 19, 2024 1

If you introduce parameters, you can keep those pure-numeric dot_m(t) , T_ram(t) helper functions as-is:

params = struct;
params.dot_m = MX.sym('dot_m')
params.T_ram = MX.sym(...)
...


p = [params.dot_m;params.T_ram;...]

f = Function('f', {x, u, p}, {dynamics(x,u,d,params)}, {'x','u', 'p'},{'x_dot'});
% In the dynamics, write params.dot_m instead of dot_m(t), and similar for others..


%Integration options
G = struct;
G.tf = T/N;

%Construct DAE
dae = struct;
dae.x = x; %define the states
dae.u = u; %define the control parameter
dae.p = p; %define paramaeters
% dae.t = t; %define the time parameter 
dae.ode = f(x,u,p); %define the RH side of ode
intg = integrator('intg','cvodes',dae, G); %Integration command

res = intg('x0',x,'p',p,'u',u); %integrate symbolically 
x_next = res.xf; %Assign the final state of x to x_next

%Returns x_next
F = Function('F',{x, u, p},{x_next},{'x','u','p'},{'x_next'});

% This loop is now devoid of any symbolic operations -> faster
for i = 1:length(t0)
	u_input = g(i, :);
	pp_num = [dot_m(i);T_ram(i)]
	x_next = F(x_current, u_input, p_num);

	x_current = x_next;
	X(:, i) = full(x_current); % Store the state at the current time step     

end

If you are willing to rewrite your helpers, you could consider using interpolant to CasADi Functions out of dot_m , T_ram, and use a time-dependant ode formulation

f = Function('f', {x, u, t}, {dynamics(t,x,u,d)}, {'x','u', 't'},{'x_dot'});
...
dae.t = t; %define the time parameter 
dae.ode = f(x,u,t); %define the RH side of ode
...

from casadi.

jgillis avatar jgillis commented on June 19, 2024

Do you mean a lot of time to implement, or to solve?

from casadi.

oaldaify avatar oaldaify commented on June 19, 2024

to solve.

from casadi.

oaldaify avatar oaldaify commented on June 19, 2024

Thank you so much @jgillis

Out of curiostiy, Is there an example on how to use (interpolant) to CasADi functions out of helper functions I can look at?

from casadi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.