MATRIXx

cancel
Showing results for 
Search instead for 
Did you mean: 

Loading %variables between runs

I've configured my file to take %variables. I do a run to get my system to a stable state using "resumeto". I do the second time concatenated run using "resumefrom". This all works fine. Now I change a few %variables and do the second time concatenated run again and I get the result of the initial second run again. When I query the variable it tells me its changed, but the simulation doesn't seem to load the %variables and execute with them. It does the same thing it did last time. My goal is to establish a stable operation (long run) and then vary items to show certain performance (short additional runs) how is this done? (THIS IS GETTING FRUSTRATING--SEE MY OTHER RECENT QUERIES)
0 Kudos
Message 1 of 4
(7,430 Views)
This seems to work for me. I created a gain block with %var="foo" and connected the IO to the "system".
In Xmath, I did the following:

foo=3;
t1=[0:.1:5]'; u1=sin(t1);
[,y1]=sim("system",t1,u1,{resumeto="f.dat"});
plot(t1,y1); #{ This showed a sine with gain of 3 }#
foo=12;
t2=[5:.1:10]'; u2=sin(t2);
[,y2]=sim("system",t2,u2,{resumefrom="f.dat"});
plot([t1;t2],[y1;y2]);

This showed a sine with gain of 3 for the first 5 seconds followed by a sine with gain of 12 for the next 5 seconds. It reported that it was resuming from "f.dat" and it also stated that it was using
%var "foo".

What block is using your %var? I know that there were issues with resume with Continuous Time Delay. Please send me more information and I'll figure out what is going on.
0 Kudos
Message 2 of 4
(7,429 Views)
The problem here is that the algebraic expression block does not reload %variables between sims. I noticed that my predecessors had used A LOT of algebraic expression blocks set to "1" with a gain block with a %variable tied to it. This clued me in to the problem and the solution...that an algebraic expression block can't be changed between sims, it runs with the original %variable value...hence the "1" and gain block. I found none of this documented in the manual (pdf version).
0 Kudos
Message 3 of 4
(7,429 Views)
Rod,
I have now reported this and the documention will be updated in the future. The reason for the behaviour is that the parameters of an Algebraic Expression block can be used as states. That is the parameter is intialized by the %var, but during the simulation the AlgebraicExpression block code can assign new values to the parameter. Thus when resume is used the parameter is restored to its value at the end of the simulation rather than to the current value of the %var.

Carl L
National Instruments
0 Kudos
Message 4 of 4
(7,430 Views)