Scientific computing loops and iterations
Show older comments
Hello
I am trying to simulate a process with the help of an m.file. The process is containing multiple structures created previously, although i think the looping sequence I am using has a fault in the way i structure it.
The process is as follows
Initially there is the main if loop which if satisfied it will enclose the consequential simulations:
if Demand <= Ewave; % this is the main limitation to be satisfied
count = length(Ewave) % Based on the length of the input file to create a counter for the loops
for count = (1:count-1)
if E_comp>P_comp
m_air_flow = (P_comp_joule *E_comp_joule*n_isc*n_mech)/(Cp_air*T_amb*((Press_r^inverse)-1));
T_out_comp = T_amb*(1+(1/n_isc)*((Press_r^inverse)-1));
elseif E_comp<=P_comp
m_air_flow = (P_comp_joule*E_comp_joule *n_isc*n_mech)/(Cp_air*T_amb*(Press_r^inverse));
T_out_comp = T_amb*(1+(1/n_isc)*(Press_r^inverse));
end
end
E_to_store = E_comp*Default.n_comp;
E_to_store_joule = E_to_store * 1000000;
count = length(E_to_store_joule)
for count = (1:count-1)
% This is the main portion of interests, the initial values are to calculated once for the 1st iteration
M_cavern(count) = E_to_store_joule(count) / (Cp_air*T_amb*(Press_r^inverse)-1);
P_cavern(count) = Default.P_cavern;
T_cavern(count) = Default.T_cavern;
% Then the 1st iteration results are used, and from that point on the counter has to ensure that the next iteration will use the previous quantity to calculate the new quantity
M_cavern(count+1) = M_cavern(count)+(m_air_flow-m_air_flow*Default.dm);
P_cavern(count+1) = P_cavern(count) - (Default.dP*Press_r);
T_cavern(count+1) = T_cavern(count) - (Default.dt*T_cavern(count));
end
Essmin = Load.N_ex *ho;
Vssmin_MWh =Essmin/DOD;
Vssmin_joule = Vssmin_MWh*3600000;
mass_flow_guar = (Vssmin_joule *P_cavern*DOD)/(ho*T_cavern*R_g);
if count==1
Tt3(count) = T_cavern+(T_cavern.*n_pre);
Tt4(count) = (Cp_air/Cp_gas)*(lamda*Ma/((lamda*Ma)+1))*...
Tt3a+(Hu/(((lamda*Ma)+1)*Cp_gas));
if Tt4(count)=<Ttmax;
Tt5(count) = Tt4(count)*(1-n_isT*(1-(1/(expansion_ratio^inverse))));
end
end
end
As you can see, my focus is to create a loop sequence which i can expand later on in various loops, the initial quantities are calculated (1st) then until the end of the (Nth) iteration the process should be 1st,2nd=(2nd-1*,,) .... Nth=(Nth-1* ...)
Can anyone help me, in suggesting or if i has faulty set-up the looping sequence.
thank you in advance
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!