openmodelica - 在 OpenModelica 中建模 RLC。错误 - 复杂和真实之间的类型不匹配
问题描述
2021 年 4 月 28 日编辑
我试图在 OpenModelica 中构建 RLC 链。当我在中输入几个函数时"equation"
,出现错误(见注释)我在上面声明了一些变量,但错误并没有消失
有公式
model Lab5
extends Modelica.Icons.Example;
type Voltage=Real(unit="V");
type Current=Real(unit="A");
type Resistance=Real(unit="Ohm");
type Capacitance=Real(unit="F");
type Inductance =Real(unit="H");
parameter Modelica.SIunits.Resistance R=100 "Resistance";
parameter Modelica.SIunits.Inductance L=1 "Inductance";
parameter Modelica.SIunits.Voltage Vb=24 "Total DC Voltage";
parameter Modelica.SIunits.Capacitance C=1e-3 "Capacitance";
Voltage V;
Current i_L;
Current i_R;
Current i_C;
Current icomp;
equation
Z1_f=Modelica.ComplexMath.'sqrt'(Complex(re=-1)*(2*Modelica.Constants.pi*f*L*(1/(2*Modelica.Constants.pi*f*C)));
** //Error:
Type mismatch in equation Z1_f=Modelica.ComplexMath.'sqrt'(Complex.'*'.multiply(Complex(-1.0, 0.0),
Complex.'constructor'.fromReal(L / C, 0.0))) of type Real=record Complex
Real re;
Real im;
end Complex;.**
Z2_f=R;
KPF=Z2_f/(Z1_f+Z2_f);
APF=ModelicaReference.Operators.'abs(KPF)';
FPF=Modelica.ComplexMath.arg(KPF);
V = i_R * R;
C * der(V) = i_C;
L * der(i_L) = Vb - V;
i_L = i_R + i_C;
annotation(
uses(Modelica(version = "3.2.3")));
end Lab5;
我尝试更改语法并制作了以下代码:
Z1_f=Modelica.ComplexMath.'sqrt'(Complex*Complex(re=2*Modelica.Constants.pi*f*L*(1/(2*Modelica.Constants.pi*f*C))));
但是现在这个错误:
Operator overloading requires exactly one matching expression, but found 0 expressions:
但是,如果我将一个复合体分配给另一个复合体的括号中的一个复合体,从而分配 1 个参数(而不是 0,如上一个错误),那么该错误再次指代错误组合的构造函数以及从复合体到实数的转换。
Z1_f=Modelica.ComplexMath.'sqrt'(Complex(Complex(re=(2*Modelica.Constants.pi*f*L*(1/(2*Modelica.Constants.pi*f*C))))));
The are 2 big errors:
Type mismatch for positional argument 1 in Complex(re=Complex.'constructor'.fromReal(L / C, 0.0)). The argument has type:
record Complex
Real re;
Real im;
end Complex;
expected type:
Real
Complex.'constructor'.fromReal(re=Complex.'constructor'.fromReal(L / C, 0.0)). The argument has type:
record Complex
Real re;
Real im;
end Complex;
expected type:
Real
我怎样才能解决复数和实数变量之间的这个问题O?因为在 Modelica 中有很多复杂数据和真实数据之间的方程。
解决方案
这似乎是家庭作业,所以我会给你一些提示。
- 不用定义 pi,而是使用 Modelica.Constants.pi。
- ModelicaReference 只是一个文档库,您不能从那里使用任何(引用的)运算符,请删除 ModelicaReference.Operators。和引号
- 您需要使用正确的类型(Real 或 Complex)声明出现在方程式部分中的所有变量,您现在缺少很多变量
- ModelicaReference.Operators.'abs(KPF)' -> abs(KPF)
- 据我所知,您使用的是复数,为此您需要使用 Complex
- 对于您使用的 Complex 运算符:Complex 运算符和Modelica.ComplexMath,即 Modelica.ComplexMath.'sqrt'(Complex(re=-1, im=0))
推荐阅读
- vb6 - 如何在VB6中使用复选框数组
- json - 通过逗号分隔符 Flutter 解析 JSON 字符串
- php - GuzzleHttp\\Exception\\ClientException:客户端错误:`POST 导致 `400 Bad Request` 响应:\n{"@context":"\\/api\\/contexts
- python - docker container jupyter lab,如何添加其他包?
- docker - 如何取消docker容器暴露端口
- reactjs - 在本机反应中使用时刻
- web - 动态颜色变化
- javascript - 为什么对象属性在循环中设置不正确?
- ios - RNCamera 在 iOS 中崩溃
- python - 如何在非常大的数据库上使用 mongodb 查询操作(有 3 个分片,每个分片大约 260-3 亿)