필터 지우기
필터 지우기

I'm stuck with this proplem. Variable used before it's defined.

조회 수: 1 (최근 30일)
Akbar
Akbar 2018년 6월 21일
댓글: Walter Roberson 2018년 6월 22일
I have a differential equation(ODE) represented as a directed graph. The ODE is not known, only its graph representation is given. ODE function is to be derived from the directed graph object. Nodes of the graph are operations like: sum, product, constant, gain... And the edges represent the variables. There is only one starting node (with one output only) whose output corresponds to "x" (or state variable of ODE). And there is one end node (with one input only) whose input corresponds to "dx" (or the first derivative of "x"). So I am trying to get equation by traversing the graph starting from the leaves (i mean terminal nodes) which also include start node. Lets say in the first iteration i scan 10 leave nodes and write the variables in m-file. Ex.: if a leave is just a constant (say 5.4), then i create a variable const1 = 5.4; After scanning some of the leaves i delete them, then i end up having the next set of leave nodes. I continue until I have no nodes left.
Shortly, the m-file i am creating is a differential equation function file. The problem is that at some points during the iteration the m-file has error like this:
function dx = myFunction(~,x,temperature,pressure)
const1 = temperature;
const2 = pressure;
addnode = (const1 + const2)*const3;
const3 = 0.03;
...
dx = ...
Here you see that const3 is defined after it has been called. I know that const3 has to be defined first, but im not sure how to do that. I get a list of terminal nodes, scan them and write the equations. Then delete scanned nodes and proceed to next set of leave nodes... Is there a way to somehow suspend the execution of line containing "addnode" untile "const3" is defined?
  댓글 수: 6
Walter Roberson
Walter Roberson 2018년 6월 22일
Please do not close questions that have an answer.

댓글을 달려면 로그인하십시오.

답변 (1개)

Steven Lord
Steven Lord 2018년 6월 21일
What you're describing sounds a lot like a Simulink model. Perhaps you should represent your differential equation graph that way? See this documentation page for a simple example.

카테고리

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

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by