Message Boards Message Boards

Interpret results of Extracting System Equations in SystemModeler?

Posted 8 years ago

Hi, When extracting System Equations using : WSMModelData["tempB1", "SystemEquations", t], my result is difficult to interpret, and there appears to be more equations than necesssary (way more ;-)

1) Is there any way to extract a condensed set of system equations ? 2) Is there a guide on interpreting the nomenclature of the equations (significance of special characters) ?

Please see attached System Modeler file and images.

Kind Regards,

John

Attachments:
POSTED BY: john massucci
6 Replies

For SystemModeler I'd recommend reading through the product documentation, available both in-product and on http://reference.wolfram.com/system-modeler/

For Mathematica, I think this question on the Mathematica StackExchange site has a fantastic set of links to both get started and learn Mathematica/Wolfram Language in-depth: http://mathematica.stackexchange.com/questions/18/where-can-i-find-examples-of-good-mathematica-programming-practice

That StackExchange site in general is a great place to learn Mathematica.

POSTED BY: Malte Lenz

I fixed your notebook (attached). First, the % refers to the output of the last evaluation. I would avoid it at most costs -- it is useful for interactive use of Mathematica but the preferred approach is to assign a variable to something. % works well until you use it out of order one time and you have a bug that is hard to find. Replace

StateResponse[ssM, UnitStep[t], t]
Plot[Evaluate[%], {t, 0, 10}, PlotRange -> All]

with

ans = StateResponse[ssM, UnitStep[t], t]
Plot[Evaluate[ans], {t, 0, 10}, PlotRange -> All]

Next,you are misusing Module[]. Module is meant for procedures to make variable local to the procedure. There are two mistakes here, First you are using module at the input prompt. For what you are doing, creating a statespace model and plotting its response, I would either do it all at the input prompt without the module, or make a procedure that has your module and return some result (i.e. the statespace model, the response, or even the plot, or a list of all of the above). The second issue is that you accidentally created a list instead of a series of operations:

In the attached notebook, I kept your Module structure but you had commas in the wrong place -- you were constructing a list of actions when what you really want is a sequence of steps -- I removed the {} and put semicolons after each line. A Module should look like this:

Module[{localvar1, localvar2},step1; step2; step3;...]

You had

Module[{localvar1, localvar2},{step1, step2, step3, ...}]

which for many reasons can have some strange results (like you were observing). After the initial example, I showed what I think is what you were looking for -- construct the matrices with symbols, then pass the symbolic matrices to a procedure that substitutes the numbers and generates the responses (returning a list of the statespace model and its plotted response). Note you could return anything you wanted in the list such as the raw data (ans), the numerical matrices, etc.

The procedure looks like this: first define a,b,c,d in terms of m1,m2,k then:

stateSpacePlotter[aMatrix_, bMatrix_, cMatrix_, dMatrix_, m1val_, 
  m2val_, kval_] := Module[{ans, ssM},
  ssM = StateSpaceModel[{aMatrix, bMatrix, cMatrix, 
      dMatrix} /. {m1 -> m1val, m2 -> m2val, k -> kval}];
  ans = StateResponse[ssM, UnitStep[t], t];
  {ssM, Plot[Evaluate[ans], {t, 0, 10}, PlotRange -> All]}]


stateresp = stateSpacePlotter[a, b, c, d, 10, 100, 10]

I hope this helps

Attachments:
POSTED BY: Neil Singer
Posted 8 years ago

Malte,

One last request (if possible) could you give me some pointers with regards to plotting specific state responses. I have copied the use of "%" in my plot command, and not sure how that is working w.r.t the state space matrix. Please see attached.

Could I thank you again for that very impressive first response ;-)

Kind regards,

John

Attachments:
POSTED BY: john massucci
Posted 8 years ago

Malte,

Could you recommend a good book on SystemModeler ? Your best three books on Mathematica ? ;-)

Kind regards,

John

POSTED BY: john massucci
Posted 8 years ago

Many thanks Malte !!

POSTED BY: john massucci

Let's start with the naming of symbols. To keep the hierarchy information from the model intact in the equations in Mathematica, a few special symbols are used:

  • "up pointer" that looks like a small triangle, which replaces the "." notation in Modelica
  • "underbracket" that looks similar to an underscore, which replaces the "_" in Modelica symbol names

There are a few ways to get a more condensed set of equations.

The most obvious one is to insert the numerical values of all parameters:

eqs = WSMModelData["temp_B_1", "SystemEquations", t];
pars = WSMModelData["temp_B_1", "ParameterValues"];
neqs = eqs //. pars

Which will eliminate all the parameters: Eliminated parameters

You can simplify knowing that the time variable will be larger than 0:

neqs2 = FullSimplify[neqs, t >= 0]

time>0

To do further processing we have to filter out the equations handling events:

{events, otherEqs} = {Select[neqs2, ! FreeQ[#, WhenEvent | If] &], 
  Select[neqs2, FreeQ[#, WhenEvent | If] &]} 

Then we can run Eliminate to eliminate variables we are not interested in. Here is an example where I have chosen to eliminate some internal variables from the equation system:

sotherEqs = 
 Eliminate[
  otherEqs, {m2\[UpPointer]flange\[UnderBracket]b\[UpPointer]s[t], 
   m1\[UpPointer]flange\[UnderBracket]a\[UpPointer]s[t], 
   m1\[UpPointer]flange\[UnderBracket]b\[UpPointer]f[t], 
   m2\[UpPointer]flange\[UnderBracket]a\[UpPointer]s[t], 
   k1\[UpPointer]s\[UnderBracket]rel[t]}]

simplified equations

To make things more easily readable, it may help to show equations in a column:

List @@ sotherEqs // Column

column of equations

Please note the warning that you received on the first evaluation of WSMModelData about algorithms. In this case, there is an initial algorithm in the pulse component that is not represented in the equations in Mathematica.

POSTED BY: Malte Lenz
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract