主要内容

Defining Component Equations

装备的ation Section Purpose

等式部分的目的是在组件的变量,参数,输入,输出,时间和这些实体的时间导数之间建立数学关系。在整个仿真过程中,执行SIMSCAPE™文件的方程部分。

Note

您还可以通过使用该方程来指定仅在模型初始化期间执行的方程式(Initial=true)属性。有关更多信息,请参阅Initial Equations

SIMSCAPE语言方程式由两个与==运算符连接的表达式组成。与常规分配操作员(=)不同,==操作员指定两个表达式之间的连续数学平等(有关更多信息,请参阅指定数学平等)。The equation expressions may be constructed from any of the identifiers defined in the model declaration. You can also access global simulation time from the equation section using thetimefunction.

For a list of MATLAB®您可以在“等式”部分中使用的功能,请参阅金宝app支持的功能

指定数学平等

SIMSCAPElanguage stipulates semantically that all the equation expressions returned by the equation section of a Simscape file specify continuous mathematical equality between two expressions. Consider a simple example:

equations Expression1 == Expression2; end

Here we have declared an equality between表达式1表达式2。左侧和右侧表达式是任何有效的MATLAB表达式(请参阅下一节for restrictions on using the relational operators:==,<,>,<=,> =,〜=,&&,||)。The equation expressions may be constructed from any of the identifiers defined in the model declaration.

The equation is defined with the == operator. This means that the equation does not represent assignment but rather a symmetric mathematical relationship between the left- and right-hand operands. Because == is symmetric, the left-hand operand is not restricted to just a variable. For example:

component MyComponent [...] variables a = 1; b = 1; c = 1; end equations a + b == c; end end

以下示例在数学上等同于上一个示例:

component MyComponent [...] variables a = 1; b = 1; c = 1; end equations 0 == c - a - b; end end

Note

装备的ation expressions must be terminated with a semicolon or a newline. Unlike MATLAB, the absence of a semicolon makes no difference. In any case, Simscape language does not display the result as it evaluates the equation.

Use of Relational Operators in Equations

在里面上一节we discussed how==用于声明数学平等。但是,在Matlab中,==yields an expression like any other operator. For example:

(a == b) * c;

wherea,b, 和c表示标量双值,是合法的MATLAB表达式。这意味着,采取logical测试产生的价值a’s equivalence tob,将此价值胁迫到双倍的并乘以c。Ifa是相同的b,然后这个表达将返回c。Otherwise, it will return 0.

另一方面,在MATLAB中,我们可以使用==twice to build an expression:

a == b == c;

这个表达式是模棱两可,但MATLAB==其他关系运营商留下了联想,因此该表达被视为:

(a == b)== c;

之间的微妙区别(a == b) == ca == (b == c)在MATLAB中可能很重要,但在方程式中更为重要。因为使用==在Simscape语言中很重要,为避免歧义,以下语法:

component MyComponent [...] equations a == b == c; end end

is illegal in the Simscape language. You must explicitly associate top-level occurrences of relational operators. Either

component MyComponent [...] equations (a == b) == c; end end

或者

component MyComponent [...] equations a == (b == c); end end

是合法的。无论哪种情况,括号中的数量都等同于方程另一侧的数量。

With the exception of the top-level use of the==操作员,==和other relational operators are left associative. For example:

组件myComponent [...]参数a = 1;b = 1;c = false;结束变量d = 1;末端方程(a == b == c)== d;结尾

is legal and interpreted as:

组件myComponent [...]参数a = 1;b = 1;c = false;结束变量d = 1;端等式((a == b)== c)== d;结尾

方程维度

表达式在==操作员不必是标量表达式。它们必须是相同的大小,或者必须是标量。例如:

方程[...] <3x3表达式> == <3x3表达式>;[...] 结尾

是合法的,并引入了9个标量方程。方程式表达式:

equations [...] <1x1 Expression> == <3x3 Expression>; [...] end

is also legal. Here, the left-hand side of the equation is expanded, via scalar expansion, into the same expression replicated into a 3x3 matrix. This equation expression also introduces 9 scalar equations.

但是,方程式表达式:

方程[...] <2x3表达式> == <3x2表达式>;[...] 结尾

是非法的,因为左侧和右侧表达式的大小不同。

装备的ation Continuity

The equation section is evaluated in continuous time. Some of the values that are accessible in the equation section are themselves piecewise continuous, that is, they change continuously in time. These values are:

  • variables

  • inputs

  • 输出

  • time

Piecewise continuousindicates that values are continuous over compact time intervals but may change value at certain instances. The following values are continuous, but not time-varying:

  • parameters

  • 常数

Time-varying countable values, for example, integer or logical, are never continuous.

Continuity is propagated like a data type. It is propagated through continuous functions (see金宝app支持的功能)。

Working with Physical Units in Equations

In Simscape language, you declare members (such as parameters, variables, inputs, and outputs) as用单位的价值,以及方程式自动处理所有单元转换。

但是,经验公式通常采用非企业指数,其中基础是无单位或已知单位的指数。使用这些类型的公式时,将基数转换为无单位值价值功能,然后在需要时重新申请。

例如,以M^3/s的流量为单位,以下公式在PA中给出压降。

p == k * q^1.023

wherepis pressure,qis flow rate andkis some unitless constant. To write this formula in Simscape language, use:

p == {k * value(q,'m^3/s')^1.023,'pa'}

这种方法不论其实际单位如何p或者q,只要它们分别与压力和体积流量相称。例如,实际流速可以以每分钟加仑的速度为单位,该方程仍将起作用并自动处理单位转换。

Related Examples

More About