Jack
Jack

Reputation: 1232

How to describe a derivative of dy/dx in Modelica?

I am working on a simple model which includes a derivative of dy/dx, but in Modelica, I can't write this equation directly, I could use the combination of x=timeand der(y), but I think this is a compromise because of limitation of Modelica language.

My question is: Is there another better method to describe derivative in Modelica?

Here is the code:

model HowToExpressDerivative "dy/dx=5, how to describe this equation in Modelica?"
  Real x,y;
equation 
  x = time;
  der(y) = 5;
end HowToExpressDerivative;

I also tried to use der(y)/der(x) to express dy/dx, but there is an error when x equals time^2.

model HowToExpressDerivative "dy/dx=5, how to describe this equation in Modelica?"
  Real x,y;
equation 
  x=time^2;
  der(y)/der(x)=5;
end HowToExpressDerivative;
Error: The following error was detected at time: 0

Model error - division by zero: (1.0) / (der(x)) = (1) / (0)

Error: Integrator failed to start model.
... "HowToExpressDerivative.mat" creating (simulation result file)

ERROR: The simulation of HowToExpressDerivative FAILED

Upvotes: 2

Views: 371

Answers (1)

Hans Olsson
Hans Olsson

Reputation: 12517

Given enthalpy h and crank-angle phi you could replace dh/dphi=... by:

  der(h)/der(phi)=...

However, even if correct that formula will break down when the engine is standing still (der(phi)=0), so it is not ideal.

An alternative would be to rewrite the formulas. Looking more closely the formula seems to be:

  dh/dphi=(\partial a/\partial T)*dT/dphi+...

which suggests that they could be rewritten as:

  der(h)=(\partial a/\partial T)*der(T)+...

Upvotes: 5

Related Questions