Why use intermediate terms in Simscape?

조회 수: 12 (최근 30일)
Jan Kragbæk
Jan Kragbæk 2017년 9월 25일
편집: Sebastian Castro 2017년 9월 25일
Hi I'm writing my own blocks in Simscape and have come across intermediate terms. I have included a code snippet as demo:
equations
let
Re = V*D*rho/mu;
in
x == y*Re;
end
Re == V*D*rho/mu;
x == y*Re;
end
What is the difference of have my equations in "let/in" instead of just having it in equations?
/Jan

답변 (1개)

Sebastian Castro
Sebastian Castro 2017년 9월 25일
편집: Sebastian Castro 2017년 9월 25일
There is an efficiency/memory vs. traceability difference.
If you defined Re explicitly as an intermediate variable, you need to allocate memory to that variable and track its value at each time step. The advantages
  1. You can log the variable and view it later with tools like sscexplore.
  2. It will show up in the block's "Variables" tab so you can set its initial condition, and you can see the initial value in the Variable Explorer.
If you use a let section, it basically inlines all that code and treats it as if it were just one big equation, as below. It is more efficient, but then you can't log the value for debugging/posterity.
x == y*V*D*rho/mu;
- Sebastian

카테고리

Help CenterFile Exchange에서 Troubleshooting에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by