Search code examples
modelicadymolaopenmodelica

Why does the "der()" operator in Modelica apply to the time variable only?


I build a simple to model in Dymola, but I got confused about the der() operator, why does the der() operator apply to the time variable only? What if I want to use the derivate to other variables

In the following code, if I want to calculate dy/dx(derivative of y to x), how should I do this?

model A
  Real x, y, z;
equation
  x=10;
  y=sin(x);
  z=der(y);
end A;

enter image description here


Solution

  • Partial derivatives are supported via functions. See chapter 12.7.2 in Modelica Spec 3.4: Partial Derivatives of Functions.

    You have to move the equation of interest into the algorithm section of a function. Your example could look as follows:

    model A
      Real x, z;
    
      function f1
        input Real a;
        output Real b;
      algorithm 
        b :=sin(a);
      end f1;
    
      function der_f1 = der(f1, a);
    
    equation 
      x = 10;
      z = der_f1(x);
    end A;