Code for iteration doesn't work
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi everybody, I need support for Matlab iteration code. In particular, I'd like to calculate "lambda_v_ratio" parameter in this code:
m=1.5; %politropic exponent
pc_ad=120000; %intake pressure
z_ad=5000; %%quota di adattamento
eta_c=0.8; %compressor efficiency
eta_mc=0.9; %compressor mechanical efficiency
eta_mt=0.9; %turbine mechanical efficiency
Lc = cpa*T_ad/eta_c*((pc_ad/p_ad)^((k-1)/k)-1); %compressor work
for j=1:length(z)
if z(j)<=z_ad
Tc(j) = T(j)+(Lc/cpa); %intake temperature
pc(j)=pc_ad; %intake pressure
else
Tc(j) = T(j)+(Lc/cpa);
beta(j) = (1+((Lc*eta_c./(cpa.*T(j))))).^(k/(k-1)); %pressure ratio
pc(j)=beta(j)*p(j);
end
rho_c(j) = pc(j)/(R*Tc(j)); %intake density
mu(j) = (pc_ad/p0)*((T0./Tc(j)).^0.5); %correct density
lambda_v(j) = lambda_v0* ((T(j)/T0).^0.5); %altitude volumetric efficiency w/o turbocompressor
lambda_v_ratio(j)=0.8;
lambda_v_tc(j) = lambda_v(j)*lambda_v_ratio(j); %volumetric efficiency due to turbocharging
air_flow_rate(j) = lambda_v_tc(j)*rho_c(j)*iV*n/(2*60);
air_mass(j) = lambda_v_tc(j)*rho_c(j)*V; %per cylinder
fuel_mass(j) = air_mass(j)/alfa;
v1(j)= (V+V0)/air_mass(j);
v2(j)=v1(j)/r;
p2(j)=pc(j)*(r^k);
T2(j) = p2(j)*v2(j)/R;
T3(j) = (T2(j)*alfa*cpa+eta_b*Hi*1000000)/(cpg*(1+alfa));
v3(j) = V0/(air_mass(j)+fuel_mass(j));
p3(j) = R*T3(j)/v3(j);
v4(j) = (V+V0)/(air_mass(j)+fuel_mass(j));
p4(j) = p3(j)*((v3(j)/v4(j))^k2);
T4(j) = v4(j)*p4(j)/R;
ps(j)= p4(j)/4;
ps2(j)=((-lambda_v_ratio(j)+1)*m*pc(j)*(r-1))+pc(j);
I'd like to calculate "lambda_v_ratio(j)" so that ps(j) and ps2(j) are almost equal (ps(j) and ps2(j) are both functions of lambda_v_ratio(j) and they have to converge). I tried with this code:
while (abs(ps(j)-ps2(j)))<100
lambda_v_ratio(j)=lambda_v_ratio(j)+0.001
but it didn't work. Start value of lambda_v_ratio(j) is 0.8. Any suggestion? Thanks for your support.
3 commentaires
Walter Roberson
le 10 Déc 2017
It would probably make more sense to put most of the code into a function and then fzero on the difference between the two values.
Réponses (1)
Antonio Tricarico
le 10 Déc 2017
Modifié(e) : Walter Roberson
le 10 Déc 2017
4 commentaires
Walter Roberson
le 13 Déc 2017
fzero() cannot be used with vector-valued functions. fsolve() can be used with vector-valued functions, in which case it would attempt to solve all of the equations simultaneously. In situations where you have an equation to be solved over a range of values, you would iterate fzero using one value each time.
Voir également
Catégories
En savoir plus sur Web Services dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!