MATLAB While循环收敛

时间:2015-03-16 18:58:11

标签: matlab iteration convergence

我正在尝试编写一个while循环迭代,以便在我的值收敛时停止。当新值与上一个值只有1%时,我希望代码停止。这是迭代关系:

Iteration

到目前为止,这是我的代码:

% Given values
clear all
clc
Tt4 = 3250
pi_c = 25
alpha = 0.5
M_0 = 1.6
h = 40 
T0 = 390.01
a_0 = 967.68
g_c = 1.4
g_t = 1.3
Cpc = 0.24
Cpt = 0.296
h_pr = 18400
M_6 = 0.4
pi_Mmax = 0.96
eta_m = 0.99
eta_b = 0.99
% From table 6.2
pi_dmax = 0.96
e_c = .9
e_f = .89
pi_b = 0.95
eta_b = 0.999
e_t = 0.89
pi_n = 0.97
eta_m = 0.995

% Calculations
R_c = ((g_c-1)/g_c)*Cpc
R_t = ((g_t-1)/g_t)*Cpt
V_0 = a_0*M_0
tao_r = 1+((g_c-1)/g_c)*M_0^2
pi_r = tao_r^(g_c/(g_c-1))
eta_r = 1-0.075*(M_0-1)^1.35
pi_d = pi_dmax*eta_r
tao_l = (Cpt*Tt4)/(Cpc*T0)
tao_c = pi_c^((g_c-1)/(g_c*e_c))
eta_c = (pi_c^((g_c-1)/g_c)-1)/(tao_c-1)
f = (tao_l-tao_r*tao_c)/((eta_b*h_pr)/(Cpc*T0)-tao_l)

% Iteration for tao_f
tao_f = (tao_r*(alpha-(tao_c-1))+eta_m*(1+f)*tao_l)/(tao_r*alpha + eta_m*              (1+f)*tao_l/((pi_c*pi_b).^((g_t-1)*e_t/g_t)))
tao_fi = (tao_r*(alpha-(tao_c-1))+eta_m*(1+f)*tao_l)/((tao_r*alpha + eta_m*(1+f)*tao_l/((pi_c*pi_b).^((g_t-1)*e_t/g_t)))*(tao_f).^(((g_c*(g_t- 1)*e_t*e_f)/g_t*(g_c-1))-1))

while abs((tao_f)-(tao_fi)) > .2
    tao_ff = (tao_r*(alpha-(tao_c-1))+eta_m*(1+f)*tao_l)/((tao_r*alpha + eta_m*(1+f)*tao_l/((pi_c*pi_b).^((g_t-1)*e_t/g_t)))*(tao_f).^(((g_c*(g_t-1)*e_t*e_f)/g_t*(g_c-1))-1))
end 

我是matlab和编码的新手,我知道我的代码卡在无限循环中,但我不确定原因。

非常感谢任何帮助!

0 个答案:

没有答案