Main Content

本页翻译不是最新的。点击此处可查看最新英文版本。

方程

编写方程以表示自定义组件行为

组件文件中 equations 部分的目的是建立组件的变量、参数、输入和输出、仿真时间以及每个实体的时间导数之间的数学关系。

同样,域文件中的 equations 部分用于建立域中势变量、参数和中间值之间的数学关系。域方程传播到相应域类型的节点。

组件方程和域方程的语法相同。Defining Component Equations提供了有关使用 Simscape™ 语言编写方程的一般信息。Domain Equations提供了特定于域方程的信息。

语言语法

assertProgram customized run-time errors and warnings
delayReturn past value of operand
derReturn time derivative of operand
equationsDefine component or domain equations
functionReuse expressions in component equations and in member declarations of domains and components
ifSpecify conditional equations, assignments, annotations, and conditional sections in component files
.ifPerform element-wise conditional operations with array-type predicates (自 R2023b 起)
integPerform time integration of expression
intermediatesDefine intermediate terms for use in equations
scatteredlookupReturn value based on interpolating unstructured set of data points (自 R2023a 起)
tablelookupReturn value based on interpolating set of data points
timeAccess global simulation time
valueConvert variable or parameter to unitless value with specified unit conversion

主题

  • Defining Component Equations

    The purpose of the equations section in a component file is to establish the mathematical relationships between the variables, parameters, inputs, and outputs of the component, the simulation time, and the time derivatives of each of these entities.

  • Simple Algebraic System

    This example shows implementation for a simple algebraic system.

  • Use Simulation Time in Equations

    This example shows how you can access global simulation time from the equation section.

  • Using Conditional Expressions in Equations

    You can specify conditional expressions in equations or conditional assignments to intermediates by using if and .if statements.

  • Using Intermediate Terms in Equations

    Textbooks often define certain equation terms in separate equations, and then substitute these intermediate equations into the main one.

  • Using Lookup Tables in Equations

    You can use the tablelookup function in the equations section of the Simscape file to interpolate input values based on a set of data points in a one-dimensional, two-dimensional, three-dimensional, or four-dimensional table.

  • Programming Run-Time Errors and Warnings

    Use the assert construct to implement run-time error and warning messages for a custom block.

  • Initial Equations

    Specify additional equations to be executed during model initialization only.

  • Simscape Functions

    Use Simscape functions to reuse expressions in equations and member declarations of multiple components.

  • Import Symbolic Math Toolbox Equations

    Example of using Symbolic Math Toolbox™ software to solve the physical equations, generate code in the format appropriate for the Simscape language equation section, and incorporate the generated code into the equation section of a component file.

  • Domain Equations

    Specify additional equations to propagate to all the components that have nodes of the corresponding domain type.