使用所有可能的组合

发布于 2024-12-10 02:31:54 字数 873 浏览 1 评论 0原文

所以我想弄清楚如何使用,

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,:)

我真的很感激一些帮助 谢谢

So im trying to figure out how to be able to use,

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(:)];

this gives me all possible combinations of from my orginal parameters

I need to plug each combination of parameters into many equations is whats the best way to do that?

for example if i want to pull out the 1st row and plug the corresponding values into say for example;

%# 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)

Im not sure but would I some how use Allcombinations(n,:)

I would really appreciate some help
Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

轮廓§ 2024-12-17 02:31:54

您可以使用逐元素运算符计算所有可能组合的所有内容去:

%# 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)

You can calculate everything for all possible combinations using element-wise operators in one go:

%# 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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文