A Slight but Likely-Crucial Problem about MATLAB Simulink derivative Block

Aug. 29, 2023

Recently, I encounter a problem while debugging a MATLAB Simulink model for my research, i.e., simulation results of the same model are convergent by solving from the perspective of “integration”, but are divergent by solving from “derivative”. This phenomenon ever seemed to appear in my past modeling experience, but I did not figure out why it is. So today, I model a simple model to get into it.

For sinusoidal wave $y(t) = \sin(t)$, we have:

\[y'(t)=\cos(t),\ \int_0^t\sin(x)\mathrm{d}x=1-\cos(t)\]

Therefore, I use a Sine Wave block to generate sine wave, followed by respectively performing integration (by integrator block) and derivation for it (by derivative block) , and then observe the results.

image-20230829135417062

image-20230829140431401

We could find that the $y’(0)$ equals 0, but not 1 which we expect based on analytical solution. I reckon it is caused by the numerical derivative-calculated strategy in MATLAB, which make $y(0^-)=y(0)$ and thereby $y’(0)=0$.

This could be found more clearly from recorded integration data:

1
2
3
4
5
6
7
>> out.dsine.Data(1:5)
ans =
         0
    1.0000
    1.0000
    1.0000
    1.0000

And likewise, this phenomenon reproduces in another simple model:

image-20230829141101738

Actually, I am not much for sure that it is only or main reason resulting in the convergence of results of complicated model with derivative block, but I think it is part of causes and should be noted.

On the other hand, the integration results only relates to Initial Condition (IC), which we could easily set in integrator property dialog. A sample shows bellowing:

image-20230829145316592

image-20230829145105206

So to my mind, using integrator block to describe system equation as much as possible, rather than derivative block, is a better choice as a fault value always appears in initial condition of derivative output, probably leading to divergent results, despite the fact of numerical algorithms for integration is much more complicated than that for derivative.