方程中的多个因变量,在for循环MATLAB中循环

时间:2017-11-24 22:21:14

标签: matlab loops for-loop dependencies

好吧,我试图用MATLAB找到变量集:ed,ec,ef,efn,et,en,这样我理论推力和实际推力之间的差异就小于.001。即使满足要求,我的代码也永远不会退出我的while语句。有什么想法吗?

    clear; clc;

B=5; Prf=1.5; M=.85; QR=43400000; Prc=30; Ta=288.2; Pa=101300; T04=1700; R=287; %ed=.97; ec=.85; et=.9; en=.98; 

% Turbojet Efficiencies and gammas 
gd=1.4; gc=1.33; gb=1.35; gt=1.33; gn=1.36; ActSpecificThrust = 800; ThSpecificThrust = 1020; g=1.4; gf=1.4; 

% Bypass Efficiencies (g/((g-1)*R)) T02 = Ta*(1+((g-1)/2)*M^2); 

while abs(ThSpecificThrust - ActSpecificThrust) >= .001
    for ed = 0.8: .05: .95
        for ec =.8:.05:.95
            for ef=.8:.05:.95
                for efn=.8:.05:.95
                    for et=.8:.05:.95
                        for en=.8:.05:.95

P02 = Pa*(1+ed*(T02/Ta-1))^(gd/(gd-1)); 
P03 = P02*Prc; T03 = T02*(1+(1/ec)*(Prc^((gc-1)/gc)-1)); 
f = (T04-T03)/((QR/1107)-T04); P04 = P03; P08 = P02*Prf; T08 = T02*(1+(1/ef)*(Prf^((gf-1)/gf)-1));
uef = (2*efn*(gf/(gf-1))*R*T08*(1-(Pa/P08)^((gf-1)/gf)))^(1/2); 
T05 = T04-(T03-T02)-B*(T08-T02); 
P05 = P04*(1-(1/et)*(1-(T05/T04)))^(gt/(gt-1)); 
T06 = T05; P06 = P05; P7=Pa; 
ue = (2*en*(gn/(gn-1))*R*T06*(1-(P7/P06)^((gn-1)/gn)))^(1/2);
u = M*(g*R*Ta)^(1/2);
ThSpecificThrust = (1+f)*ue+B*(uef)-(1+B)*u;
%TSFC = f/ASpecificThrust;
%ep = (SpecificThrust*u)/((1+f)*ue^2/2+B*uef^2/2-(1+B)*u^2/2); 
%eth = ((1+f)*ue^2/2+B*uef^2/2-(1+B)*u^2/2)/(f*QR); 
%e0 = ep*eth;

                        end
                    end
                end
            end
        end
    end
end

1 个答案:

答案 0 :(得分:-1)

您是否检查过满足要求?

您为每个for循环创建的向量只有五个值(0.8,0.85,0.9,0.95),这些值的组合可能无法给出预期值。

再次检查代码我发现使用while循环条件的ThSpThrust值是使用每个for循环的最后一个值(0.95)计算的。基本上你在检查abs(ThSpThrust(0.95,0.95 ...) - AcSpThrust)> = 0.001

找到正确的值后,您应该使用标志和break语句。但是你需要休息一下。

我会使用fminsearch来最小化function = abs(ThSpThrust - AcSpThrust)。