2011-10-16 59 views
1

所以我試着去弄清楚如何能夠使用的,利用所有可能的組合

parameters = {[6 12 18 24], [1200 1800 2400 3000], [80 90 100],[80 90 100],[80 90 100]}; 

[r T3 Ec Et Er ] = ndgrid(parameters{:}); 

Allcombinations = [r(:) T3(:) Ec(:) Et(:) Er(:)]; 

這給了我的所有可能的組合從我的原單參數

我需要將各組合的參數代入許多方程式是最好的方法來做到這一點?

例如,如果我想拉出第一行並插入相應的值,例如說;

%# Note: k, Cp and T1 are predefined constants 

Ec1=Ec/100; 

Et1=Et/100; 

Er1=Er/100; 

T2s=T1*(r)^((k-1)/k); 

T4s=T3*(1/r)^((k-1)/k); 

T2a=((T2s-T1)/Ec1)+T1; 

T4a=T3-Et1*(T3-T4s); 

wca=Cp*(T2a-T1); 

wta=Cp*(T3-T4a); 

T5s=Er1*(T4a-T2a)+T2a; 

qcombustion=Cp*(T3-T5s); 

qregen=Cp*(T5s-T2a); 

qin=qcombustion+qregen; 

fprintf ('\n Net Work Output=%6.2f', wnet) 

fprintf ('\n Back Work Ratio=%4.2f', rbw) 

fprintf ('\n Thermal Efficiency=%4.2f\n', Eth) 

林不知道,但我一定會如何使用Allcombinations(n,:)

我真的很感激一些幫助 謝謝

回答

1

可以計算一氣呵成使用element-wise operators所有可能的組合都:

%# Note: k, Cp and T1 are predefined constants 

parameters = {[6 12 18 24], [1200 1800 2400 3000], [80 90 100],[80 90 100],[80 90 100]}; 

[r T3 Ec Et Er ] = ndgrid(parameters{:}); 

%# turn arrays into vectors 
r = r(:); 
T3 = T3(:); 
Ec1=Ec(:)/100; 
Et1=Et(:)/100; 
Er1=Er(:)/100; 

%# perform calculations using element-wise operators 

T2s=T1.*(r).^((k-1)/k); 

T4s=T3.*(1./r).^((k-1)/k); 

T2a=((T2s-T1)./Ec1)+T1; 

T4a=T3-Et1.*(T3-T4s); 

wca=Cp*(T2a-T1); 

wta=Cp*(T3-T4a); 

T5s=Er1.*(T4a-T2a)+T2a; 

qcombustion=Cp*(T3-T5s); 

qregen=Cp*(T5s-T2a); 

qin=qcombustion+qregen; 

%# Warning: These statements will produce a lot of output! 

%# If you want to show the output for, say, combination #5 
%# use e.g. wnet(5) 

fprintf ('\n Net Work Output=%6.2f', wnet) 

fprintf ('\n Back Work Ratio=%4.2f', rbw) 

fprintf ('\n Thermal Efficiency=%4.2f\n', Eth) 
+0

謝謝。以及關於結果亞我知道它應該是一個426x5矩陣,我需要繪製他們都非常感謝你 –