Can't retrieve value from previous time step.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am doing a energy storage and transport project in simulink in matlab. It is formed by a file which contains constant variables and an interactive model that attempts to simulate the flow of energy of this sytem, this is possible because inside of this model formulas and calculations can be implemented. The system consist of 5 blocks. Transport to supply, injection, storage, extraction, transport to demand, inside of each block you add the different formulas/calculations. The system also accounts for power losses. I am stuck in the storage subsystem.
I have a function block that simulates the storage. I have as inputs some constants and the variable power supply from a data file. I have as outputs the energy lossses and the energy storage. My type of storage is a water thermal battery (very simple). I have time step of 5mins, which means that there is a point every 5 mins, in the data file time there is data for 525600 minutes (one year). Every time step energy is added tothe storage, raising the temperature, the thing is in my code i can only take into account the enegy of the storage at that time step. I would like to retrieve the temperature of the previous step and add it to the new one, like this i will have the energy being stored in the system, but i dont know how to do this.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1708946/image.png)
function [DStorage, EdotStorage]= Storage(PtoStorage, PfromStorage, kWater,TEnv, tankheight, tankradius, mwateronetank,cWater, ITank)
PreviousT = 0; %This should retrieve me the temperature of the tank in the previous time step, or the output from the previous step is even fine (from here I can calculate the temperature rise, make it a variabe and add it ot "Atank")
ATank= 2*pi*tankradius*(tankradius+tankheight); %Area of the tank
Ttank= TEnv + ((PtoStorage/125)/((mwateronetank)*cWater)) + PreviousT ; %Actual temperature of each tank
Dofonetank = ((kWater* ATank * ((Ttank-TEnv))/ITank)); %Power loss due to conduction in one tank
DStorage= Dofonetank*125; %Power loss due to conduction in all tanks
EdotStorage = PtoStorage - PfromStorage - DStorage; %Amount of energy in the storage
Antworten (1)
Jasvin
am 10 Jun. 2024
An approach with the "Unit Delay" block does make sense here, but I'll suggest an alternate approach using the "Data Store" blocks.
You can define the current temperature of the tank, which I assume is "Ttank", as an output of the "MATLAB Function" block. Then you can send this data to a "Data Store Write" block, so that it gets stored in a Data Store, say "temp".
Now you can redefine the function to take "PreviousT" as an input, and connect a "Data Store Read" block with the same data store name "temp" to this input.
To summarize, your function definition will now look like:
function [DStorage, EdotStorage,Ttank]= Storage(PtoStorage, PfromStorage, kWater,TEnv, tankheight, tankradius, mwateronetank,cWater, ITank,PreviousT)
The output line for "Ttank" will go to the "Data Store Write" block and the input line for "PreviousT" will come from "Data Store Read" block.
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!