My while loop doesn't seem to end, though the expression is satisfied.
Ältere Kommentare anzeigen
Hi, I'm coding an iterative model and am having problems with the following while loop. I'm trying to get the loop to stop running once CO2percentout1(i)=CO2percentout(i-1) within a tolerance. I've defined the CO2percentout1 to be from 1:1000.
- I've defined i to be 2 initially.
- From manually inspecting the code the CO2percentout1 seems to converge within 15 iterations to at least 4 decimal place accuracy but still the code doesn't finish executing.
- All variables except the ones that are inputs for the other functions(i.e. CO2percentout2,Algae_in_2) have been inputted and those that are iteratively determined have been given initial guesses outside the loop.
Any help is much appreciated, Kiran
function [Algae_Product,c] = Threestage(tot_gas_flow_LPM,CO2_percent_feed,Water_flow,C01,C02,C03,V1_L,V2,V3,H1,H2,H3)
V1=V1_L;
Height1=H1;
Height2 = H2;
Height3= H3;
tot_gas_flow=tot_gas_flow_LPM;
CO2percentout1 = 1:1000;
CO2percentout1(:)=0;
CO2percentout1(1) = CO2_percent_feed-.6*CO2_percent_feed;
CO2percentout2 = CO2_percent_feed-.5*CO2_percent_feed;
CO2percentout3 = CO2_percent_feed-.3*CO2_percent_feed;
i=2;
c1 = 1:49;
c2 = 1:49;
c3 = 1:49;
while abs(CO2percentout1(i) - CO2percentout1(i-1)) > 0.001
%for i = 1:50
[CO2percentout1(i),Algae_in_2,c1] = stage1(CO2percentout2,V1,tot_gas_flow,Height1,C01,Water_flow);
[CO2percentout2,Algae_in_3,c2]=stage2(CO2percentout3,V2,tot_gas_flow, Height2, C02,Water_flow,Algae_in_2);
[CO2percentout3,Algae_Product,c3] =stage3(CO2_percent_feed,V3,tot_gas_flow,Height3,C03,Water_flow,Algae_in_3);
i=i+1;
end
c=[c1 ;c2 ;c3];
end
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!