MATRIXx

cancel
Showing results for 
Search instead for 
Did you mean: 

How to save final states with simout

The simout function description (html and manual) indicates that it is capable of saving initial or final states, however it does not say how to save the final states or indicate to the function how to do this. How do I indicate that I want the final states? (When I run simout, it acts like its assuming initial states).
0 Kudos
Message 1 of 4
(7,620 Views)
When you use the Simout function you are quirying the state of the model as it exists. If you did not immediately prior run a simulation then you will have the output as the initial conditions. If you want the final states then you will have to run a simulation.

If you are doing this you may want to incorporate into your reportior the use of the resumeto and resumefrom keywords. See the following from the manual:

Linearizing About a Final Operating Point

To linearize a single-rate system at a certain operating point, you must first perform:

y = sim(model,t,u)
sys = lin(model,{resume});

The resume keyword indicates that the linearization operating point will be the final operating point of the previous simulation. To save the operating point at th
e end of the simulation specify the lin options resumeto=filename and resumefrom=filename.

Alternatively, you can simulate the model until you reach the desired operating point:

y = sim(model,t,u);

Find the state at that operating point:

[x] = simout(model);

Linearize around the operating point:

sys = lin(model,{u0=u(length(t),:),x0=x})

Now it sometimes becomes useful to obtain the operating point without running a simulation for this purpose there is a full featured trim function that is documented pretty well in the online manual... Search "trim"
Garrett Thurston
gthurston@foliage.com
Phone: 781.993.5540
Message 2 of 4
(7,620 Views)
There is a way of saving the entire state vector during the simulation?
0 Kudos
Message 3 of 4
(7,620 Views)
You could do this a variety of ways. If you simply want the final states then you could do as shown in the previous answer.

If you wanted the entire state vector as a function of time then you could go to each integrator and take the output and write to a variable then at the top level read from the variable and post it to an output.

You could keep it compact by using and indexed variable, see the manual on indexing into a variable.

Another thing that you could do, and I'd have to check on the syntax, but there is a simulation command that writes all the %variables out onto the Xmath Stack at the end of a simulation. Using something like this you would not even have to plumb the variable as an output but simply write to it and then use the pr
oper simulation command. This would be a bit more complicated because you would have to have an indexing method for each time step for each state to accrue the state as a function of time in the wtv block. Fairly easy for discrete systems somewhat more challenging for continuous time systems, maybe.

Finally, you don't have the opportunity to see the states in the filters or other blocks in this way unless you decompose them into some form, cononical, etc., that allows you access to those states.


If any of this needs more clarification other than the manual then let me know and I can look into more specifics.
Garrett Thurston
gthurston@foliage.com
Phone: 781.993.5540
0 Kudos
Message 4 of 4
(7,620 Views)