# Number of variables vs number of equations in Simscape components

5 views (last 30 days)
Federico Toso on 10 Mar 2023
Edited: J Chen on 21 Mar 2023
When I define a new custom component in Simscape, as a general rule I take care that the number of equations in the "equations" section match the number of variables in the "variables" section. So far so good.
However, while studying the source code of some components of the Foundation Library, I discovered that this requirement is not always satisfied. For example: "convection_port.ssc" is the source code for a convection port component, which is part of the "Thermal Liquids" library. The code shows a clear mismatch between the number of variables and the number of equations (specifically: there are more variables than equations). However, this component is obviously a valid one.
In conclusion, I was wondering if there is a general rule that must be followed when setting the number of variables & equations for a custom Simscape component, so that its validity is guaranteed.
I searched the documentation online, but I could not find a detailed answer so far
Thanks
##### 0 CommentsShow -1 older commentsHide -1 older comments

Sign in to comment.

### Answers (1)

J Chen on 20 Mar 2023
Edited: J Chen on 21 Mar 2023
For a Simscape component, the variables include variables in the variables AND nodes sections as in this example. The number of equations in the "equations" section doesn't need to match the number of variables in the "variables" section. Look at the resistor example: there are 6 variables (p.v, p.i, n.v, n.i, i, v), 2 eqs in the equations section and 2 eq in the branches section (i=p.i, p.i=-n.i). So we need to know 2 variables (e.g., p.v, n.v) in order to solve the problem. This is consistent with a real resistor, i.e., if two variables are specified (e.g., voltages at the two terminal), all the variables are defined.
##### 1 CommentShow NoneHide None
Federico Toso on 20 Mar 2023
According to Simscape documentation, branches section does not introduce new equations, it only modifies the already-present node equations.
Even in the resistor example you quoted, the number of variables declared inside the component file (i and v) matches the number of equations in the equations section (if you exclude the assert statement)

Sign in to comment.

### Categories

Find more on Foundation and Custom Domains in Help Center and File Exchange

R2022b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!