I was working on an example of simulink's thermal model here, where I converted it into an AC and shared my steps in this post.
As I was working on it, I noticed that no matter how much I vary my setpoint temperature or my combfort levels, the output always starts from around 85 F and drops as shown in the figure below.
I think this could be an initial value issue but I checked all the initial values in the initialization .m file and changed them to suit my AC (Tin_init=26, T_heater=15 for AC).
The equations behind the model are shown in the official documentation of the model, but there was no mention of anything that would explain the plot always starting from 85. Any idea what could cause this?
Thanks
The model is set-up with a Model Workspace, which means that when the model is being initialized it looks there first, before looking in the Base Workspace. As per the picture below, the Model Workspace has a value for TinIC, which means this value is used, not any value that you may have in the Base Workspace. To reinitialize the workspace you need to press that button indicated in the image below.
In your case you most likely want to remove the Model Workspace, and just have the model parameters picked up from the Base Workspace. That way you can make changes and have them reflected in the simulation.
Related
Initialization could be very cumbersome and easily lead to divergence. A simple strategy is to run the simulation when building a part of the whole system and use the simulation results to modify guess values.
Here is what I got in the PPT from Francesco Casella and the book from Daniel Bouskela.
I found that I could use an option in Dymola as follows, but instead of using the initialization result, I wanna use the result when reaching a steady state. So I'd like to use a python script to extract the result from the .mat result file, then modify the iteration variables automatically. But the key problem is that I don't know when I add more components in my model, the iteration variable set of existing components would change, I don't know what kind of effect would this causes.
Anyone got opinion on this issue, welcome to answer this question.
So my question is where should I find the python
You can use the end values (= steady state) of the simulation result in order to create a new initialization (Dymola Manual 1, section 2.5.12) . If the component names are the same in the sub system model and the total model, you can run the script created in the subsystem model on the larger system model as well. But you have to check if your models have initial equations that hinder an initialization from the outside (see section 4.2 in https://2012.international.conference.modelica.org/proceedings/html/pdf/ecp12076927_KruegerMehlhaseSchmitz.pdf)
It should also be possible to initialize it steady state. Instead of providing initial values for a state x and fixing it, you can provide initial equations for the derivatives such as der(x) = 0;
With that setup activate Save Initial Results and you should be good to go.
I am trying to make a simulation in Simulink, with the fuzzy model.
As inputs, I have set four time series variables from the workspace (compatible to simulink after performing Simulink.Timeseries function): every row of the variables has a linked time starting from 0 to 10566 (seconds, I believe). How can I set the sample time in simulink source block in order to pick every exact case without interpolation?
Thank you for your kind answers,
Phalaen
Are you using the From Workspace block? If so, it's simply a matter of specifying the sample time in the block parameters and unticking "Interpolate data". You can also display the sample time information of the model to check which sample time each block is using, see View Sample Time Information in the documentation.
I have a model and I need to change the sample time of each block that I currently have in my Simulink model.
The problem is that I have so many blocks that make changing this parameter for each individual one cumbersome. Is there a means to change it for a group of blocks?
One more thing, what is the default sample time indicated by "-1"?
This can be done quite easily. In general it is a good practise to be aware of the simulation time, simulation steps and solver you are using in simulink simulations, as sometimes the simulation can go wrong just because of the solver, or because of the simulation step size.
To change all this parameters (and the step size, what I assume is your "sampling time")
you need to go to the Solve Pane that looks like this:
You can see in there how "Max step size" and "min step size" are there, set to auto. This two exist because some odes (as ode45 in this case) use variable step size, but if you want fixed step size you can change the solver to ode1 or ode3 for example.
About that -1 thing... You should not change each blocks sample rate unless you really meant to. When do yo want to do this? In general when you want the sample rate of THAT specific block to be smaller than the rest. So if you have a simulation that is running the whole system at 1e-2 sample rate, and you have an specific block thatneeds to run just every second, then you change the sample rate. Else the default is -1, which means the same sample rate that you have set up in the Solve Pane.
So:
ALWAYS be aware of whats going on in the Solve Pane
Dont change those "-1" unless you really meant to
I'm using the simulink block From Workspace to read in some audio data provided by a script. I have formatted the data in a matrix with 2 columns, the first is the timestamp and the second is the data.
In the configuration paramaters, I have specified Fixed-Step and Discrete solver. The Start time and Stop also need to be configured manually and don't seem to come from the data.
Also, in the From Workspace block configuration, I need to specify the sample time (1/44100) or I get a warning if I specify -1, to inherit from the data and then get strange sample times.
So, how can I get simulink to use only the sample times in the matrix and use the first and last timestamps as the start and stop time of the simulation?
You should be able to do what you want by doing the following:
Firstly note that your problem is by definition not fixed step, hence you cannot use a fixed-step solver, which by definition is ... fixed-step.
You must use a variable step solver.
Assuming your (2 column) input data is called simin then set the start and stop times to be simin(1,1) and simin(end,1) respectively.
In your From Workspace block set the sample time to be 0 (which should have been the default).
Also de-select the Interpolate data option; and set "Form the output after final data value by:" to zero (you won't be using anything past the end of your data set so this should be OK.
Then you need to tell the solver to take additional steps to those that it would naturally want to take.
Do this on the Data Import/Export pane of the Model Configuration Parameters.
Near the bottom of the pane there is a selection box and an edit box for doing this.
Note however that this does not prevent the solver from taking steps at other time points, it just forces it to take additional steps at the times you specify.
But because you have your From WOrkspace block to not interpolate this shouldn't be a problem either. You should put simin(:,1) in here so that the solver is guaranteed to take steps at the time points in your input data.
Note that if you want an input block that only samples at the time points in the simin time vector then the only way to do this is to write an S-function that uses the mdlGetTimeOfNextVarHit method to tell the solver what the next sample time (for this block) should be.
I am running a simulink simulation using the fixed-step discrete solver. I've even specified the fixed-step size. I save some data via a "To Workspace" block (I've used the Scope to save to workspace as well with equivalent results). When I look at the time data in the object, the time is not monotonically increasing.
The time value is constant for 5-10 samples, then continues. Any ideas why this happens?
I took a screen shot of the Time vector. You can see it goes flat, then continues, then is flat. I expected a single line.
I asked on the Mathworks site as well. I'll update both if I get an answer.
EDIT: I am working with Mathworks now too. They did show me how to visually inspect sample times. Navigate to Format > Sample Time Display > All. This will show all of the sample times in the simulation.
This problem was caused, at least partly by the existence of algebraic loops. Since Simulink was recalculating the algebraic loops, the output was capturing these changes.
I was able to click the "minimize algebraic loop occurrences" in the
Configurate Parameters > Model Referencing
and my loops were eliminated. This is a YMMV answer, but its the best I've found working with Mathworks support.