## 2 Buck Converter Modeling
The approximation means that the values of state variables are calculated at specific points in time separated by a finite but small value \(dt\). Several numerical methods are identified and well documented in the literature. They range from simple methods, such as first-order methods like explicit Euler, to more complex ones, such as those of the Runge-Kutta group. The ones mostly used among the Runge-Kutta methods are second-order Runge-Kutta and fourth-order Runge-Kutta. The order \(n\) of the methods refers to the global error of the numerical calculation and means that the numerical error is of the order of \(\mathcal{O}(dt^{n})\), where \(dt\) is the step size. The explicit Euler method estimates the slope of \(f(t)\) only at \(t_{n}\) and has an order of 1. Higher-order methods estimate it at several points around \(t_{n}\): second-order Runge-Kutta performs two estimations, and fourth-order Runge-Kutta performs four estimations. These two methods deliver each more accuracy than lower-order ones, at the cost of additional computational complexity. In this case, the objective was to obtain the maximum accuracy, and the fourth-order Runge-Kutta method was chosen. The calculation of \(v_{C}\) and \(i_{L}\) using this method can be expressed with the pseudo-code of Algorithm 1. By inspecting the lines 30 and 31 in Algorithm 1, the increments of the state variables can be defined as follows:  
\[\frac{dv_{C}}{dt} =\frac{i_{C}}{C} \tag{1}\]0 \[\frac{dv_{C}}{dt} =\frac{i_{C}}{C} \tag{1}\]1```
1:functioncalculateRK4(\(iL,\
u C,dt,R,L,C,S1,S2,v_{s}\))
2:if\(S1=closed\) OR (\(S1=open\) AND \(S2=open\) AND \(iL<0\)) then\(\triangleright\) First mode
3:\(K1C\gets iL/C-\
u C/(R\times C)\)
4:\(K1L\leftarrow(v_{s}-\
u C)/L\)
5:\(K2C\leftarrow(iL+K1L\times dt/2)/C-(\
u C+K1C\times dt/2)/(R\times C)\)
6:\(K2L\leftarrow(v_{s}-(\
u C+K1C\times dt/2))/L\)
7:\(K3C\leftarrow(iL+K2L\times dt/2)/C-(\
u C+K2C\times dt/2)/(R\times C)\)
8:\(K3L\leftarrow(v_{s}-(\
u C+K2C\times dt/2))/L\)
9:\(K4C\leftarrow(iL+K3L\times dt)/C-(\
u C+K3C\times dt)/(R\times C)\)
10:\(K4L\leftarrow(v_{s}-(\
u C+K3C\times d))/L\)
11:elseif\(S2=closed\) OR (\(S1=open\) AND \(S2=open\) AND \(iL>0\)) then\(\triangleright\) Second mode
12:\(K1C\gets iL/C-\
u C/(R\times C)\)
13:\(K1L\leftarrow-\
u C/L\)
14:\(K2C\leftarrow(iL+K1L\times dt/2)/C-(\
u C+K1C\times dt/2)/(R\times C)\)
15:\(K2L\leftarrow-(\
u C+K1C\times dt/2)/L\)
16:\(K3C\leftarrow(iL+K2L\times dt/2)/C-(\
u C+K2C\times dt/2)/(R\times C)\)
17:\(K3L\leftarrow-(\
u C+K2C\times dt/2)/L\)
18:\(K4C\leftarrow(iL+K3L\times dt)/C-(\
u C+K3C\times dt)/(R\times C)\)
19:\(K4L\leftarrow-(\
u C+K3C\times d)/L\)
20:elseif\(iL=0\)then\(\triangleright\) Third mode: \(iL=0\) during a deadtime
21:\(K1C\leftarrow-\
u C/(R\times C)\)
22:\(K1L\gets 0\)
23:\(K2C\leftarrow-(\
u C+K1C\times dt/2)/(R\times C)\)
24:\(K2L\gets 0\)
25:\(K3C\leftarrow-(\
u C+K2C\times dt/2)/(R\times C)\)
26:\(K3L\gets 0\)
27:\(K4C\leftarrow-(\
u C+K3C\times dt)/(R\times C)\)
28:\(K4L\gets 0\)
29:endif
30:\(iL\gets iL+dt\times(K1L+2\times K2L+2\times K3L+K4L)/6\)\(\triangleright\) Return \(iL_{n+1}\)
31:\(\
u C\leftarrow\
u C+dt\times(K1C+2\times K2C+2\times K3C+K4C)/6\)\(\triangleright\) Return \(\
u C_{n+1}\)
32:endfunction
```

**Algorithm 1** Calculation of following value of \(v_{C}\) and \(i_{L}\) with fourth-order Runge-Kutta method

## 3 Sources of Errors

### Generic Sources of Errors

The implementation of an accurate hardware-in-the-loop model must take into account the sources of errors, how large their contribution is and to what extent they can be reduced. The designer of a hardware-in-the-loop system must perform the trade-off between better accuracy and limiting factors, such as resource usage and timing constraints, which translate into cost of the system. Some sources of errors are generic to all hardware-in-the-loop models. They include the numerical method chosen, the value of \(dt\), the numerical representation of state variables, and the modeling or not of n-th order losses.