Debugging is taking too long| Iterative Newton-Raphson Method

11 visualizaciones (últimos 30 días)
Vickson Leji
Vickson Leji el 6 de Dic. de 2018
Comentada: Vickson Leji el 6 de Dic. de 2018
So I'm trying to find a value iteratively using the Newton-Raphson Method. It's working, I think, but it's just taking a really long time and the closer it gets to it's true value the slower it becomes. Is there anyway to speed up this process. This is my function code.
function T3= pt3(MC, MH, MO, Hr, yycc,y,ycc,ymin, T2,T1,Urp,P1,V1,ry)
CO = [299180, 37.85, -4571.9, -31.1;309070, 39.29, -6201.9, -42.77]
CO2 = [56835,66.27 -11634, -200; 93048, 68.58, -16979, -220.4]
H2O = [88923, 49.36, -7940.8, -117; 154670, 60.43, -19212, -204.6]
N2 = [31317, 37.46, -4559.3, -34.82; 44639, 39.32, -6753.4, -50.24]
O2 = [43388, 42.27, -6635.4, -55.15; 127010, 46.25, -18798, -92.15]
%ycc= MC+(MH/4)-2*MO
%ymin = ycc - MC/2
R=8.31451
%y=yycc*ycc;
yfuel=1/(1+4.76*y)
yair=(4.76*y)/(1+4.76*y)
ntot=(P1*V1)/(R*T1)
nfuel=yfuel*ntot
nair=yair*ntot
mfuel=nfuel*114
mair=nair*28.97
f=mfuel/mair
if y>=ymin & y<=ycc
N=[2*(ycc-y),2*(y-ymin), MH/2, 0, 3.76*y];
else y > ycc
N=[0, MC, MH/2, y-ycc, 3.76*y]
end
T3 =T2+1
F=1
while abs(F)> 1e-8
if T3<=1600
COp = CO(1,1)+CO(1,2)*T3+CO(1,3)*log(T3);
CO2p = CO2(1,1)+CO2(1,2)*T3+CO2(1,3)*log(T3);
H2Op = H2O(1,1)+H2O(1,2)*T3+H2O(1,3)*log(T3)
N2p = N2(1,1)+N2(1,2)*T3+N2(1,3)*log(T3)
O2p = O2(1,1)+O2(1,2)*T3+O2(1,3)*log(T3)
dFT = N(1)*((CO(1) -R)+CO(2)*T3)+N(2)*((CO2(1) -R)+CO2(2)*T3)+N(3)*((H2O(1) -R)+H2O(2)*T3)+N(4)*((O2(1) -R)+O2(2)*T3)+N(5)*((N2(1) -R)+N2(2)*T3)
else T3>1600 & T3<=6000
COp = CO(2,1)+CO(2,2)*T3+CO(2,3)*log(T3);
CO2p = CO2(2,1)+CO2(2,2)*T3+CO2(2,3)*log(T3);
H2Op = H2O(2,1)+H2O(2,2)*T3+H2O(2,3)*log(T3)
N2p = N2(2,1)+N2(2,2)*T3+N2(2,3)*log(T3)
O2p = O2(2,1)+O2(2,2)*T3+O2(2,3)*log(T3)
dFT = N(1)*((CO(1) -R)+CO(2)*T3)+N(2)*((CO2(1) -R)+CO2(2)*T3)+N(3)*((H2O(1) -R)+H2O(2)*T3)+N(4)*((O2(1) -R)+O2(2)*T3)+N(5)*((N2(1) -R)+N2(2)*T3)
end
if T2<=1600
COr = CO(1,1)+CO(1,2)*T2+CO(1,3)*log(T2);
CO2r = CO2(1,1)+CO2(1,2)*T2+CO2(1,3)*log(T2);
H2Or = H2O(1,1)+H2O(1,2)*T2+H2O(1,3)*log(T2)
N2r = N2(1,1)+N2(1,2)*T2+N2(1,3)*log(T2)
O2r = O2(1,1)+O2(1,2)*T2+O2(1,3)*log(T2)
else T2>1600 & T2<= 6000
COr = CO(2,1)+CO(2,2)*T2+CO(2,3)*log(T2);
CO2r = CO2(2,1)+CO2(2,2)*T2+CO2(2,3)*log(T2);
H2Or = H2O(2,1)+H2O(2,2)*T2+H2O(2,3)*log(T2)
N2r = N2(2,1)+N2(2,2)*T2+N2(2,3)*log(T2)
O2r = O2(2,1)+O2(2,2)*T2+O2(2,3)*log(T2)
end
Air= [ 27.5 .0057]
Oct= [38.4 .429]
phi_airT1 = (Air(1) - R)*log(T1)+ Air(2)*T1
phi_fuelT1=(Oct(1) -R)*log(T1)+ Oct(2)*T1
phi_airT2 = (Air(1) - R)*log(T2)+ Air(2)*T2
phi_fuelT2=(Oct(1) -R)*log(T2)+ Oct(2)*T2
dphi_air= ((Air(1)-R)/T2)+ Air(2)
dphi_fuel= ((Oct(1)-R)/T2)+ Oct(2)
F = Urp + N(1)*281400 + N(1)*((COp-COr)-R*(T3-T2))+ N(2)*((CO2p-CO2r)-R*(T3-T2))+ N(3)*((H2Op-H2Or)-R*(T3-T2)) + N(4)*((O2p-O2r)-R*(T3-T2))+N(5)*((N2p-N2r)-R*(T3-T2))
T3=T3-(F/dFT)
end
  2 comentarios
Jan
Jan el 6 de Dic. de 2018
Editada: Jan el 6 de Dic. de 2018
You mention "debugging" in the titel - what do you debug?
Many of the lines do not have a trailing semicolon. I assume, the most time is spent with writing to the command window.
You do not provide the values for: MC, MH, MO, Hr, yycc,y,ycc,ymin, T2,T1,Urp,P1,V1,ry . Therefore we cannot run your code.
Instead of calculating e.g. log(T3) in each line, compute it once and store the result in a variable.
Vickson Leji
Vickson Leji el 6 de Dic. de 2018
Well I mentioned debugging, because when I pause the iterations theres a s "quit debugging" option, so I asssumed that's what it was. I'm not well versed in Matlab, so I'm sure I could be wrong.
I have a another code that uses this function code but I can give you the values
MC=8
MH=18
MO=0
Hr=-5089100;
yycc=.7
y=12.5
ycc=12.5
ymin = ycc - MC/2
T2=602.2065
T1=300
Urp=-5097780;
P1=100
V1=.0005
ry=9.0
And alright that makes sense I'll try that. Thank you

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by