# WSM_KeyNewMathematicaFeatures

0 (0 Likes / 0 Dislikes)

Welcome to this presentation—
key new Mathematica features for SystemModeler.
My name is Malte Lenz
and this presentation is going to be about how you can get the most out of new Mathematica features
in combination with SystemModeler features.
So here is an overview of what this presentation is going to contain
There is going to be a section about control systems—
how you can use those in Mathematica to interact with SystemModeler models—
there’s going to be a section about how you can use new visualization
and interactivity features in Mathematica, how you can use new signal processing features,
as well as how you can use new time series features together with SystemModeler.
In this section we’re going to show to get a model from SystemModeler into Mathematica by linearizing it,
then designing a PID controller for that model
and then getting it back into SystemModeler to simulate it with that controller.
For that we’ll use this DC Motor model,
which has some input, “v”, that governs the voltage in the circuit that in turn turns the flange in the motor.
And we want to regulate the speed of this motor.
So what we do is we linearize the model with “WSMLinearize”,
which gives us a state-space model in Mathematica.
We then design a PID controller for the motor with the new Mathematica feature,“PIDTune”.
We just feed the system to that function and we get a PID data object back.
We see the parameters that are chosen for our PID controller as well what tuning rule it used.
We can then get back those parameters from the PID data object
and feed them back into the SystemModeler with “WSMSetValues”.
We can then show the complete model with PID controller in SystemModeler
by calling “WSMModelCenter” of this model.
We see that we have our DC motor, which was the system that we saw earlier,
we have a PID controller, we have a reference signal,
and then we have our disturbance signal,
which adds load on the flange of the DC motor,
and finally we have an output motor speed,which shows the speed of the motor.
So that brings us to our next section—
the visualization and interactivity section where we are going show how to use interactivity
in real time simulation to simulate this motor model with our PID controller
and this disturb it dynamically with a gauge from Mathematica.
So we start a real time simulation of this motor speed model.
We add a disturbance, or a load, controlled by a manual gauge,
so a horizontal gauge we can see that we can slide this slider here on the gauge
and it varies between -1 and 1 and it changes the disturbance variable.
Then we use “SetInputs” to set the inputs for our simulation—“conn”—
which we started up here spread up here when we set the disturbance
or the load parameter to this disturbance variable for the gauge.
Finally, we do a real time plot of both the speed of the motor,
the disturbance we are controlling with our gauge, and the reference signal.
Now we’re ready to start our simulation.
We do that by pushing “play” on our simulation.
We see that blue line here is the speed of our motor—
it follows the green reference signal pretty well.
We see our disturbance, which we control with our gauge down here—
the orange one. And if we slide our disturbance,
if we slide it slowly we don’t see the motor speed varying from the reference speed at all while if we go very quickly,
add a lot of load changes quickly,we see that the motor speed actually wobbles a little
until the controller kicks in and gets it back to the reference signal.
Our next section shows how you can use filter design or signal
processing in Mathematica together with SystemModeler models.
So for this we are going to assume an external input to a model
that has been modeled with a Weiner process in Mathematica.
And we are going to sample that process, just randomly sampling it,
and retrieving a time series of this process.
And if we plot that sample process we see a pretty noisy signal,
which we want to filter with the lowpass filter.
To do that, we use a “Manipulate” of a Butterworth filter and what we do—
we have these two parameters to the Butterworth filter and omega
and we can tune these parameters interactively and see how the model reacts or how the filter reacts.
So in blue, we see the original noisy signal
and if we tune these parameters we can live see how it changes the orange signal,
which is the filtered signal.
So we are going to choose some parameters like this
and we’re going to switch to the next slide to get this filter into SystemModeler.
So we’re going to create a State Space model from this p filter, “g”, which we had in our “Manipulate”.
And we are just calling to call “WSMCreateModel”, which creates a model called “TuneFilter”
with this state space model we just designed.
We can then simulate our filter with the input of our noisy process, “e”.
And then we can plot the results, the input, and the output to the filter
and we can see the given results which we could see earlier in the “Manipulate”
but now we have a Modelica model or SystemModeler model,
which we can apply to any noisy signal like this.
In this last section we’re going to show how to use time series
and time series forecasting to predict energy production costs using a SystemModeler model
and real life input data for historic oil price from Wolfram Alpha.
So we start by recreating data from Wolfram Alpha for the daily spot oil price
and we get that data for a sample of one week.
If we do that, we get this curve of the plot, Oil Price Data,
and we see that it has its peaks and valleys but there seem to be an up-going trend overall.
Then we’re going to use this data to make a forecast for 13 weeks into the future after this data finishes.
And we’re going to use time series modeling to do that.
So we’ll use “TimeSeriesModelFit” on our data with seasonal SARIMA prediction.
And we’re going to use “TimeSeriesForecast” on that model to get a forecast into the future.
And finally, we can plot the results and we get almost the curve as before but with some adding forecasting
at the end and we see that the forecast says that the oil price is going to rise after this time.
Finally, we can use our forecast data as input to our SystemModeler model,
the “InputControlledElectricityProduction”,
which models electricity production costs based on oil price.
So if we simulate that, we can then show the fuel costs per megawatt hour by plotting that
and adding a line here from where we started to predict data.
So up to the dashed line is the real data from Wolfram Alpha
and after the dashed line is based on the data from our time series forecasting.
And we can see that our energy production costs
will actually rise based on the fact that the oil price is predicted to rise after our cutoff point.
the fact that the oil price We will also have an increased fuel cost for our oil power plant.
This presentation showed just a couple of the different ways
you can benefit from new Mathematica features in conjunction with SystemModeler.
Thank you for listening.