WSM Part 3
0 (0 Likes / 0 Dislikes)
So we'll look at how can we actually visualize
these simulation results.
So we've learned a bit about plotting certain variables
and so on but now it's time to take more complete control
of the simulation results.
We'll focus on visualization here
but this is especially good when you are doing other things as well,
such as optimization, calibration, or symbolic analysis
in the Wolfram Language. It uses the same basic concepts.
And so we'll look a bit, what are these simulation results we would be getting.
How can we use them,
and how can create some other types of simulations?
Some parametric simulations, I'll go into what that is in the end.
So first of all, we'll start by loading in a new model,
just like with the inverted pendulum.
I have a deployed string here,
and we're just calling “ImportString” and “MO”,
actually this could also be an answer to the
question whether the model gets deleted after quitting Mathematica.
You could Iconize your model in this way
and keep it in the notebook like that
but it gets unloaded, then you have to load it back in.
This model, it's text based,
and it's relatively simple,
we can ask for the...
it only has two parameters.
Actually I should start with what it is, I'm trying to model.
It's modeling a ball that is bouncing on a two-dimensional surface,
or a two-dimensional landscape.
And it has two parameters,
one is the gravity of the landscape,
and one is the restitution when the ball impacts with the surface.
It also has a few variables that we can get out from the model,
the velocity in the x-direction,
the velocity in the y-direction, the xy positions,
the gravity that is effecting the ball,
and the equations for the surface.
And we can simulate this model with some different
settings for the parameters as well as the initial values.
And this works just the same way as you did
with the parameter values in the inverted pendulum case.
We had some explicit values for the gravity and the restitution
but we also to our association, add initial values.
And since this is a dynamic model,
described by differential equations,
you need to specify where the system start…
in what states it starts in.
The interpretation in this case
is the initial position of the ball.
So we can simulate that
and get back a simulation result.
Now this SimulationDataObject, it contains
some different functions that can be used to construct results.
One thing, we can query this simulation data
is by giving it a list of variables we are interested in
and we'll see what we get.
We get a list of functions.
It looks kind of little weird when I'm zoomed in
but it's a list of two functions, one for the x variable
that contains different InterpolatingFunctions
Wolfram Language InterpolatingFunctions
that describe how the ball is moving in the x-direction
in response to…
well during different times,
and how the ball is moving in the y-direction.
So you get back different InterpolatingFunctions like that.
If we ask for something that's constant,
for example the gravity,
which is a parameter that we specified in our model,
we'll predictably get back a constant value.
You can also ask this SimulationDataObject
for the variables at specific time points.
So here I'm asking it for
points between the time 0 and time 2,
and in steps of 0.1 seconds.
And we'll get back a list
from that, predictably.
Okay, so we can use this,
we can take this list,
the same list I showed previously and we can transpose it
into x and y coordinates at different time intervals
and simply put that in a ListPlot,
and then we'll get back a trace of how the ball was moving,
this is our initial position,
and we'll get back a trace for how the ball was moving
at different time intervals in steps of 0.1 seconds.
We're also using the InterpolatingFunctions directly,
so if you remember the InterpolatingFunctions that I showed previously,
you just ask it for the variables that you're interested in.
Here I specified that we want to denote our time variable as “t”
and you can put that in another visualization function, for example
a ParametricPlot, or if you have three variables
you can put it in a parametric 3D plot.
But here we only have two,
so we get back kind of the same plot as we had previously
but now it's using these InterpolatingFunctions
to calculate the trajectory of the ball over time
from our simulation results.
In the model, this is the equation
that has been used to create this.
You can't see it right now,
but the model is bouncing off a surface.
And this here is the equation that
created that surface that was inputed into the model.
So we can create, you know,
using purely Wolfram Language you can create a Plot of that surface.
And then we can combine that with our…
we'll do a new simulation of the bouncing ball
between 0 and 8 seconds using the same parameter values as before.
And we'll ask for the trajectory from that simulation.
Now, what we can do is we can
put this plot together with the trajectory Plot
that we had up here using the show command.
So we'll ask for a ParametricPlot of the trajectory,
just like the Plot command up there.
And we'll also ask for…
we'll also input this into an Animate function,
which will animate the ball's movements over time.
And what we'll do is we'll say that the final…
only plot the ParametricPlot from time 0 to time final,
which will change, depending on the Animate.
So let me just show you how this looks.
So slow this down a bit.
So now we're animating how the ball,
from this SystemModel model,
and the trajectories that we were able to get out of the simulation results,
we're animating how it was actually bouncing off of the surface
that we had defined.
Right, so I'm sorry that I went a bit fast on the last part
but we're sending out the notebooks for this in the chat.
And we will also follow up with an email,
sending out these notebooks.
You can kind of get into them for yourself
so you can try all the things that have been shown today
as well as the last part which I unfortunately didn't have time to cover today
which is how you can create these models from scratch
from the Wolfram Language.
All of that will be sent out,
so that you can try this for yourself,
understand what is happening.
And yeah simulate the included models and expand upon that.