Simone Bertoni’s Post

View profile for Simone Bertoni

Helping Control and Software Engineers Reach their Career Goals with Training Courses and Individual Working Sessions | PID Control Expert | Control and Electrical Engineering Team Manager at Ceres

Classic Runge-Kutta method implemented in C. Let's see how to use it to run a simulation. Classic Runge-Kutta or RK4 is the most known method of the Runge-Kutta family. We can use it to simulate the evolution of a dynamic system, as an alternative to more basic methods like Euler. Let's take the simple model of a car described in https://buff.ly/3fsMaGL and refreshed in the picture below. We have shown that its motion is described by: dv/dt = (F - b * v^2) / m The RK4 provides an approach to compute y(t_n+1) starting from the knowledge of y_n and f(t, y) = dv(t)/dt. Here's the method: y(t_n+1) = y_n + T*(k1 + 2*k2 + 2*k3 + k4)/6, where t_n+1 = t_n + T Also: k1 = f(t_n, y_n) k2 = f(t_n + T/2, y_n + T*k1/2) k3 = f(t_n + T/2, y_n + T*k2/2) k4 = f(t_n + T, y_n + T*k3) In the picture below you can find: - A recap of the method - The model of the car above implemented in C with forward Euler and with the classic Runge-Kutta method - The result of a simulation that compares the continuous model implemented in Xcos (max integration time 0.01s) and the two implementations above (using T = 5 seconds) The parameters used are: m = 1000 kg b = 1 N*s^2/m^2 I limited the integration time in Xcos to 0.01s so that the result is very accurate and I chose T = 5s to push the two iterative methods to be in trouble, to see which one performs better. In this case, we can observe from the simulation result that RK4 is a lot more accurate (closer to Xcos) than Euler. A clarification on the implementation of the functions in C. The transient nature of the system is obtained by running the functions N times to generate N values of v, starting from N values of F. For example: v[i] = Car_FE(F[i], 1000, 1, 5); where i = 0 to N-1. If you enjoyed this follow me for more tips on control and embedded software engineering. Hit the 🔔 on my profile to get a notification for all my new posts. #controlsystems #embeddedsystems #softwareengineering #embeddedsoftware #controltheory #coding

  • No alternative text description for this image
Julio Bascur (M.Sc. eMBA)

Product Manager - Transmission Lines at Svenska kraftnät

3y

Adam Lind, M.Sc., P.Eng. …how about a walk down the memory lane? ;)

Ahmed A Hakeem AlMenhawy

Engineer | Multiple Engineering Credentials

3y

Thanks for sharing..Excellent Work

Vibin Jacob

18y exp in R&D Product Dev.,Thermal System(HVAC and Powertrain cooling), NVH, Vehicle Development,Testing & EV thermal.

3y

By scilab ode() in-built differential equation function 'y=ode(y0,x0,x,f)' deff('yprim=f(t,v)','yprim=(1000 -196- v*v) /1000'); t0=0; tf=140; dt=0.001; t=t0:dt:tf; v0=0; v=ode(v0,t0,t,f); plot(t,v),xgrid xlabel('$Time(s)$','fontsize',4) ylabel('$Velocity$','fontsize',4) title('$y\prime=(1000-196-v^2)/1000,\quad y(0)=0$','fontsize',4)

  • No alternative text description for this image
Laurentiu Cancel

Engineering Manager - Diagnostics, Networks and Cybersecurity

3y

If you want to see Runge-Kutta RK4 in action, check out this application: https://x-engineer.com/ It simulates an electric vehicle on a drive cycle.

Aljoša Skočir

Embedded Software Team Lead at MESI

3y

Nice. I haven't used this method since the university. But it's great to refresh it again.

Amit Deshmukh

FCEVs & EV Prototype, Testing & Validation, Homologation & NPD

3y

Thanks for sharing

Raj Maloth, M.E.Sc, P.Eng

Lead CFD Engineer| ML/AI Integration | Turbo Machines | ThermoFluids Research | Product Development | Optimization | Western University Alumni

3y

I use Runge- Kutta method to solve my system of ODE’s on daily basis at work. More stable then Euler method.

Zoran Todosijevic

Senior Software Engineer/Team Leader at IGT - Belgrade branch

3y

Next step - N body simulation using Runge Kutta :)

Shivam Dubey

Packaged App Development Sr. Analyst at Accenture[SAP EWM - SAP MM] || Ex - Capgemini

3y

Nice example One of the best method used in simulation

Omar Hatem

Senior Engineering Student || Ensono Part-Time Data Scientist || VOIS ML Engineer Intern || Technical Writer (Remote)

3y

It's one of the best methods used in simulation; keep up the good work.

See more comments

To view or add a comment, sign in

Explore content categories