MATLAB Answers

Is there a tool for drawing diagrams that connect equations?

2 views (last 30 days)
Marco Sandoval Belmar
Marco Sandoval Belmar on 1 Aug 2020
Edited: John D'Errico on 1 Aug 2020
Hi there,
I don't know how to ask this question, actually. But I have a bunch of equations and constants and are all connected somehow. Let's say the following code:
R=8.314;
n=0.412;
a=4;
m=2;
S=10;
rho=1;
F=m*a;
P=F/S;
V=m/rho;
T=(P*V)/(n*R);
Is there a way that Matlab (or maybe another language) returns you a diagram with the workflow, or something like that the figure?
Because I think any language needs to define each constant and equation in order, so I just want that order back

  0 Comments

Sign in to comment.

Answers (1)

John D'Errico
John D'Errico on 1 Aug 2020
Edited: John D'Errico on 1 Aug 2020
I don't think there is a tool in MATLAB that will take a set of equations in arbitrary order, and then create this diagram.
You could parse the equations yourself, then extracting a list of all variables, and which side of the equality they fall on. That would be sufficient to create a directed graph (not a pictorial graph) but a matrix that describes all connections between nodes, and the direction of flow for each expression. Then you would work with that graph to allow you to traverse the system. This would allow you to identify which relations must come first.
Would it work well? Probably not, as it will be difficult as hell to write when loops wre involved, recursions, etc. Building the elements of a vector in a loop might be a complicated thing to do, especially if there were function calls in there. Abither problem is what to do is the same variable name was used twice? (A sadly common thing to see, with novice programmers reusing variables multiple times, with totally different meanings in each case.)
Worse, since in MATLAB, I can define a variable name that is the same as a function name, you would need to do some pretty intelligent parsing. In some cases, the necessary parsing would be impossible to perform automatically. (I imagine I can probably come up with an example of code that would contain just such an ambiguity, that only the person who understands what the expressions mean can resolve.)
Honestly, I don't think you need the tool you want to see, as it would seem to be more of a crutch than an aid in the end. And it would not be very useful for anything complex. Far better for you to just understand the computations you need to do. Then no special tool is necessary. It is just the matter of learning to program, and a tool that allows you to not learn what you need to do will cost you more in the end than it helps.

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!