我有关于使用“衍生”注释的问题,我想问你。让我们放一个样本。
方程是这样的:
z_level = LevelZ(time);
其中 LevelZ(time) 是一个外部 C 函数,还有 LevelZ_der(time) 和 LevelZ_der2(time) 是一阶和二阶导数。
代码是这样的,它运行良好......
function LevelZ_der2
input Real t;
input Real dt;
input Real ddt;
output Real res;
external
res = LevelZ_der2(t);
annotation(Library="...", Include="...");
end LevelZ_der2;
function LevelZ_der
input Real t
input Real dt
output Real res;
external
res = LevelZ_der(t);
annotation(derivative=LevelZ_der2,
Library="...", Include="...");
end LevelZ_der;
function LevelZ
input Real t
output Real res;
external
res = LevelZ(t)
annotation(derivative=LevelZ_der,
derivative(order=2)=LevelZ_der2,
Library="...", Include="...");
end LevelZ;
...虽然出现了这些错误:
[C:/Users/Model/Model.mo:52:2-52:28:writable] Warning: Unused input variable dt in function .LevelZ_der2.
[C:/Users/Model/Model.mo:52:2-52:28:writable] Warning: Unused input variable ddt in function .LevelZ_der2.
[C:/Users/Model/Model.mo:52:2-52:28:writable] Warning: Unused input variable dt in function .LevelZ_der.
Error: Derivative of expression
Differentiate.differentiateExpSolve failed for z_level - LevelZ(time)
is non-existent.
但是,如果代码是这样的,OpenModelica 模拟会忽略导数...
function LevelZ_der2
input Real t;
output Real res;
external
res = LevelZ_der2(t);
annotation(Library="...", Include="...");
end LevelZ_der2;
function LevelZ_der
input Real t
output Real res;
external
res = LevelZ_der(t);
annotation(derivative(zeroDerivative=t)=LevelZ_der2,
Library="...", Include="...");
end LevelZ_der;
function LevelZ
input Real t
output Real res;
external
res = LevelZ(t)
annotation(derivative(zeroDerivative=t)=LevelZ_der,
derivative(order=2)=LevelZ_der2,
Library="...", Include="...");
end LevelZ;
...并出现此错误:
Error: Derivative of expression
Differentiate.differentiateExpSolve failed for z_level - LevelZ(time)
is non-existent.
什么是正确的方法,为什么?
最好的问候科尔多