Hi,

I've got some issues regarding Mathematica and System Modeler Link but I think it's mainly a Mathematica regarded question, so that there might be people who can help me even though they don't work with Wolfram System Modeler.

What I try to do:

I run a simulation in WSM (but controlled from Mathematica), at the end I want to take some values and start another Simulation with them.

So here's an example:

N1 = WSMSimulate["TestMathematica", {0, 10}] (*at the beginning I run the simulation for the period 0..10 seconds*)

The simulation "TestMathematica" has three parameters that form a vector together. In WSM they are defined this way:

Real[3] gStart;

In WSM the vector elements are addressed like this: gStart = {gStart[1], gStart[2], gStart[3]}

In contrary in Mathematica it's like this: ....gStart[[1]]

So I think that Mathematica doesn't know that the Parameters gStart[1 to 3] belong together and form a vector but rather that they are three independent parameters. But still all parameters together (and in this case there are only these 3 elements) form a vector:

MatrixForm[N1["ParameterNames"]]

leads to a column vector:

{"gStart[1]", "gStart[2]", "gStart[3]"}

At the end of the simulation I want to save 3 Values into a vector named init2:

For[i = 1, i <= 3, ++i, init2[[i]] = ToExpression[StringJoin["N1[{\"g[", ToString[i], "]\"},{10}]"]]]

so for each element this should do this:

init2[[1]] = N1[{"g[1]"}, {10}]

I would prefer something like this: init2 = N1["gStart"] but it doesn't seem to work since Mathematica doesn't seem to know that the 3 gStart elements belong to one vector.

Of course the for loop doesn't make sense for these 3 elements but this is only an example for a much more complicated simulation.

init2 (*returns this...:*)

{{{10.}}, {{20.}}, {{15.}}}

MatrixForm shows a column vector again but with brackets around each element.

Now I want to start a new simulation with init2 as parameter values:

N2 = WSMSimulate["TestMathematica", {0, 10}, WSMParameterValues -> {For[i = 1, i <= 3, i++,

ToExpression[StringJoin["\"gStart[", ToString[i], "]\""]] -> init2[[i]] ] }]

leads to this error

WSMSimulate::par: "Value of option WSMParameterValues -> {Null} should be on the form {\"par1\" -> v1, ...}."

I already tried a lot of things: I thought the vectors are different forms, but both are column vectors. Transpose[...] didn't change anything. One problem might be the curly brackets at init2, but I also tried Flatten[...] or set this manual in different forms. I didn't work. The only thing that works is to put every parameter element by itself in the equation without the for loop. But as I said, this is just an example for something more complex.

Does anybody have an idea?

Thanks in adavance! Stefan