Is there a way to come up with all the combination between 0 and 1 that sum up to equal 1?

2 visualizaciones (últimos 30 días)
Is there a way to come up with all the combination between 0 and 1 that sum up to equal 1?
  1. All combination between 0 and 1. y4 = [Ny4 Hy4 Ay4 Cy4] , if sum(y4) = 1
  2. Put Them into sum(((K-1).*y4)./(1+(K-1)*v)) = 0 to solve for v.
  3. Then x5 = y4./(1+(K-1).*v), if sum(x5) = 1
  4. finally y6 = K.*x5, if sum(y6) = 1
When I used nchoosek([0:1/10000:1],4) I get error.
Error using zeros
Maximum variable size allowed by the program is exceeded.
Error in nchoosek>combs (line 164)
P = zeros(total, k, 'like', v);
Error in nchoosek (line 123)
c = combs(v,k);
I solved this using excel solver, that is how I got the values.
% guess mole fraction for stream 4 the feed into the flash separator.
% the sum of all 4 must equal 1.
Ny4 = 0.108536069;
Hy4 = 0.772457477;
Ay4 = 0.117147745;
Cy4 = 0.001858709;
y4 = [Ny4 Hy4 Ay4 Cy4];
% K-value given
NK = 4.8;
HK = 70;
AK = .051;
CK = .32;
K = [NK HK AK CK];
% guess ratio
% v is want I want to solve for when t(v) = 0
v =.925028796;
t = sum(((K-1).*y4)./(1+(K-1)*v));
% mole fraction for stream 5 the liquid out the flash separator.
% the sum of all 4 must equal 1.
x5 = y4./(1+(K-1).*v)
testx5= sum(x5)
% mole fraction for stream 6 the vapor out the flash separator.
% the sum of all 4 must equal 1.
y6 = K.*x5
testy6 = sum(y6)

Respuestas (1)

KSSV
KSSV el 7 de En. de 2020
x = 0:1/100:1 ;
id = nchoosek(1:length(x),4) ;
thesum = sum(x(id),2) ;
% find sum == 1
idx = thesum==1 ;
iwant = x(id(idx,:)) ;
  4 comentarios
A C
A C el 8 de En. de 2020
I am sorry that I did not explain my problem. When I use 1/10000 it gives me a error.
Do you get the same errors?
x = 0:1/10000:1 ;
id = nchoosek(1:length(x),4) ;
x = x(id) ; % nx4 array of all x's
Error using zeros
Maximum variable size allowed by the program is exceeded.
Error in nchoosek>combs (line 164)
P = zeros(total, k, 'like', v);
Error in nchoosek (line 123)
c = combs(v,k);
KSSV
KSSV el 9 de En. de 2020
It might be dude to x is large and posing memory issues. You can split x into multiple parts, and get the job done.

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by