Watch videos with subtitles in your language, upload your videos, create your own subtitles! Click here to learn more on "how to Dotsub"

WSM Part 4

0 (0 Likes / 0 Dislikes)
We have just been looking at prebuilt models or models that have been imported but it's also interesting to create your own models. And a good way to do this is using the graphical modeling interface of SystemModeler but sometimes you want to do it programmatically using the Wolfram Language, because there's a lot of scripting that you can make use of in the Wolfram Language, it powers you when you are building these models, so if you want a build a large array with different models with variations of each other, you can use the scripting functionality in the Wolfram Language to build these. And I'll show you just how you can do that. And let's load in a representation of a low-pass filter since we've been talking about these electrical models. So it's just an electrical model which describes the filtering where you set the voltage, and it will have some capacitors and Operational Amplifiers, that will in the end, filter voltage spikes and so on. So it will smoothen out the voltage in these particular circuits. And we can simulate the model and see how it behaves. And previously we have changed, use these associations to change initial values, for example, the balls in the previous section, or the parameter values. You can also change inputs if you have undefined inputs like this. So this is an input to the model. Then, you can see the name here, Vi, and you can say that it goes towards a Wolfram Language function, so this can be anything that takes one argument at a time and then spits out one value. So it can be an anonymous function like this, it could be Sin, time data, TimeSeriesModel, or anything like that. Here we will just have a unit step. And we will plot the input and the output, and a unit step is a particularly good way to see how a filter filters a signal. So we have the input which is quite sharp, and then we have an output which is filtered which is over here. And then the voltage has been filtered. And the first thing if you want to create a model, one easy way to create a model is to configure a new model from a previous one. And to do this, just call the name, you take one of the system models, take a bracket and then you put an association of what you want to change in the model. So this is the same as what we do for SystemModelSimulate but it's a bit more permanent, where we actually write this we create a new model which has new parameter values or initial positions and so on. So now we got a model assigned here called newLowPass, which is a variation on the old LowPass filter here and show that they are indeed two new, we can simulate both of them and plot them together so you can actually plot models that are different models using the SystemModelPlot command, doesn't have to be different parametric simulations, it can be different models, as long as they both have the same variable that you want to plot, in this case the Vo. And when we set these parameter values in the new model, it looks like the filtering was, I guess you say we lower the filtering because now it's looking a bit… It's not filtering it as heavily. We can ask for a property from this new model that we created. We'll ask for the model name and I'm doing this to show you that if you create the model like this, you can just create a new variation on the model. It's unnamed, you haven't given it a name yet, it's living on quite hidden in the engine. If we want to, we can still find it in SystemModeler if we ask for it though but it's quite hidden among unnamed models. But if we want to promote this to something that we want to reuse later, we can give it a model name, so this will call the model newLowPass, and we'll suddenly have a model here in SystemModeler I'll show you that's called newLowPass so we just save the model name. But it hasn't been saved either, this new model that we created. But we can do that with the Export command, so just Export, the place you want to save it, and the model that you want to save and suddenly you have a location where it's saved. Right, another way you can create models is to use CreateDataSystemModel, and that is a command that takes a TimeSeries or another time function in the Wolfram Language, for example here we have a random function in the Wolfram Language, a random TimeSeries based on an autoregressive process and we can create a datamodel based on this, and the datamodel is just, you know, a set of different time intervals with an output from this model that we just created that can be connected to other parts of the system. But this can be simulated just like any model, so we will call SystemModelPlot, we will ask for this output, and it can be… It's an array actually so it can have multiple values that we will specify that we want the first value which in this case the one that we put in. Now this isn't particularly interesting on its own, what's interesting is that we can use this with a function that's called ConnectSystemModelComponents. And what this will do is it works like the graphical user interface in SystemModeler where you can connect different components together and create a completely new model but using scripting instead of graphical modeling. So, we'll create a component in this model called datamodel, and it will refer to this SystemModel up here that we created, the datamodel. And we will create a component called lowPass, which refers to the lowPassFilter that we created previously, it's not actually the one we created. And then we'll give a list of the different connections that we will have in the model and here we have a model that has been created from the Wolfram Language, and it looks like yes, here we have it. Programmatically created, simulated just like any other model and we can see how this lowPass filter filters out the output seen coming from the datamodel that we created. And this of course can be further opened up and edited in SystemModeler. So what we just created lives here in SystemModeler and we can further, you know, modify it and add new connections.

Video Details

Duration: 9 minutes and 24 seconds
Language: English
License: Dotsub - Standard License
Genre: None
Views: 3
Posted by: wolfram on Jul 12, 2018

WSM Part 4

Caption and Translate

    Sign In/Register for Dotsub to translate this video.