How do I program iteration using a for loop?
Show older comments
How do I use a for loop for iteration? My code is as follows:
%Analysis of gas turbine solar dish system
m=0.09; %mass flow rate
PR=3; %pressure ratio
eff_comp=0.8; %efficiency of compressor
cpc=1005; %specific heat capacity of cold area
cph=1100; %specific heat capacity of hot area
e=0.85; %effectiveness of heat exchanger
%Compressor
T1=288;
P1=101325;
P2=PR*P1;
Ti2=T1*(P2/P1)^(0.4/1.4); %ideal temperature at exit of compressor
T2=T1+(Ti2-T1)/eff_comp;
%Heat exchanger
T5=800; %assumed temperature at turbine exit
Q=e*cpc*(T5-T2);
T6=T5-(Q/(m*cph));
T3=Q/(m*cpc)+T2;
%Receiver
DNI=800;
Adish=39;
eff_rec=0.85;
T4=((DNI*Adish*eff_rec)/(m*cph))+T3;
%Turbine
P3=P2*(1-0.03)*101325*(1+0.05);
P4=P3*(1-0.02);
P5=P1*(1+0.05);
eff_turb=0.85;
T5V=T4-((eff_turb*T4)*(1-(1/(P4/P5))^(0.4/1.4)));
I essentially assume T5, then I eventually work out a verified T5V, and if T5V doesn't equal T5 then I want to use the previously assumed T5 to do all the calculations again until T5=T5V with a error difference of 1. How would I do this?
1 Comment
Stephen23
on 22 Mar 2017
Put the code in a function, then use fminunc.
Answers (0)
Categories
Find more on Thermal Analysis 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!