Please take a minute to review and accept our Terms of Use.
Welcome to the PLECS User Forum, where you can ask questions and receive answers from other members of the community.

Many technical questions regarding PLECS are answered on the Technical Solutions page of our website. Tutorial videos, specific application examples, and pre-recorded webinars are available on our YouTube page. Please follow us on LinkedIn for the latest Plexim news.

Why is there no Derivative block in the component library?

+1 vote
82 views
I can find an Integrator but no Derivative. What is the reason for this?
asked Jan 17 by Plexim Support Team (87 points)

1 Answer

0 votes
 
Best answer

PLECS does not provide a Derivative block because numerical derivatives have very bad numerical properties. To be reasonably accurate, they need small time steps; the automatic step-size control of a variable-step solver, however, only works for integrators but not for derivatives. Another practical issue is that a derivative amplifies noise in the system.

It is therefore preferable to formulate a problem in such a way that it can be modeled with integrators rather than derivatives.

If you absolutely must use a derivative in conjunction with a variable-step solver, you can implement one with a C-Script as follows:

Setup

  • Number of inputs: 1
  • Number of outputs: 1
  • Number of disc. states: 2
  • Sample time: 0

Code declarations

#define lastTime DiscState(0)
#define lastInput DiscState(1)

Start function

lastTime = CurrentTime;
Output(0) = 0;

Output function

if (lastTime != CurrentTime)
{
   Output(0) = (Input(0) - lastInput)/(CurrentTime - lastTime);
}

Update function

lastTime = CurrentTime;
lastInput = Input(0);

See the attached PLECS Standalone demo model for a working implementation. Notice the visible difference between the differentiated sine signal and the cosine signal. This difference will become smaller if you reduce the maximum step size in the solver settings.

answered Jan 17 by Plexim Support Team (87 points)
...