CCS Note 11: Lesson 6. Numerical Methods

Hsueh-Ju Wu 吳學儒
TI Code Composer Studio
4 min readJul 14, 2023

中文版:
https://medium.com/@k053170/numerical-methods-51c7e969a7a

Preface

This tutorial quickly introduces the concept of numerical methods, focusing on implementation methods, so there may not be rigorous content proof and description.

Buck converter numerical methods examples (with Python) https://colab.research.google.com/drive/1D6QX3_nmWHTLyygglZMVZ3SbrC1nC4Cb?usp=sharing

Introduction

The reason why numerical methods are needed in engineering is that we usually use differential equations to model systems. To know the system dynamics, we need to solve differential equations, but it may be difficult or even impossible to find the analytical solution of differential equations. In special cases, we only need numerical results and don’t need the form of the analytical solution. Furthermore, due to the powerful capabilities of modern computers, we can perform numerical calculations quickly, which may be much faster than manually finding the analytical solution. Therefore, we use numerical methods to help us solve these problems.

Common numerical methods include Euler’s Method, Improved Euler’s Method, and the Runge–Kutta Method. These three methods are first-order methods. That is, they only need to establish a derivative once to perform calculations. This article will introduce these three methods.

Euler’s Method

Firstly, the method itself is the concept of discrete approximation, so the results must have errors. The shorter the discrete time interval, or the sampling period, the closer the result is to the real solution. But conversely, the calculation amount under the same time window is greater. It is necessary to make a trade-off between the accuracy of the solution and the calculation time.

Hearing the name Euler, you should know that this method is not ordinary and must be ingenious. It essentially uses the concept of the Taylor series to make a first-order approximation of a function (that is, using the concept of the slope in two-dimensional space). And the meaning of the differential equation itself is the amount of change, so if we know the differential equation, we basically have the future information amount. Given the conditions (initial value, initial condition, and boundary, boundary condition), we can predict the future shape of the function. This is why you can find the system dynamics without knowing the analytical solution.

The following is the key formula of Euler’s method:

Then, you only need to set the sampling period (sampling period, td) and initial value (initial condition). Through algorithm iteration, you can get the values after n time intervals.

If a graphical solution is used, the relationship between each iteration can be clearly known, and it can be understood how the error is generated. Because the error will affect the starting point of the next iteration, the error will accumulate. If the error is too large, it may cause the system to diverge.

If you want to improve accuracy, the simplest way is to reduce the sampling interval td, but this will lead to an increase in the calculation amount. Is there a way to improve accuracy without reducing td?

The answer is yes. The causeof the error can be seen from the graphical solution. Because this moment’s slope is used to estimate the next set of points, but because the system is not linear, the slope estimate is inaccurate. If you can still correct the slope or find a mathematical operation that can represent the “real two points” slope situation, we can reduce the error and achieve a more accurate numerical solution. Hence, this leads to the Improved Euler’s Method.

Improved Euler’s Method

The key mentioned just now is to correct the slope. The Improved Euler’s Method is to use a rolling correction, use the newly predicted point to obtain a new set of slopes, average with the starting point slope, and obtain a method that can represent the slope between two points (the concept of pre-predicting the slope). Finally, use this corrected slope to predict a new point. It’s like doing Euler’s Method twice.

Runge–Kutta Method

Also known as the RK Method, it also uses the concept of correcting slopes to achieve more accurate numerical solutions. The feeling of introducing statistics begins, using the concept of weighted average to get the corrected slope to predict new points.

The general formula is as follows:

Euler’s Method is called the First-order Runge-Kutta method (RK1)

Improved Euler’s Method is called the Second-order Runge-Kutta method (RK2)

The commonly used RK4 method:

Usually, using RK4 is quite accurate.

--

--