问题
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;
回答1:
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;
来源:https://stackoverflow.com/questions/64262053/why-does-the-der-operator-in-modelica-apply-to-the-time-variable-only