为什么“der()"Modelica 中的运算符仅适用于时间变量? [英] Why does the "der()" operator in Modelica apply to the time variable only?
问题描述
我在 Dymola 中构建了一个简单的模型,但我对 der()
运算符感到困惑,为什么 der()
运算符仅适用于时间变量?如果我想对其他变量使用导数怎么办
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
在下面的代码中,如果我想计算dy/dx
(y到x的导数),我该怎么做?
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;
推荐答案
通过函数支持偏导数.请参阅 Modelica Spec 3.4:函数的偏导数中的第 12.7.2 章.
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;
这篇关于为什么“der()"Modelica 中的运算符仅适用于时间变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!