This is the code for 5 effect backward feed evaporator with vapor bleeding. But when I run this code I didn't get values for all iteration. Please help to get it.

조회 수: 3 (최근 30일)
T0=120;
lat0=2225.804;
Tf=108;
F=37.8;
xf=0.13;
cpf=4.19-2.35*xf;
V0=5.7;
T=rand(5,1);
x=rand(5,1);
L=rand(5,1);
V=rand(5,1);
V1=rand(5,1);
A=rand(5,1);
cp=rand(5,1);
bpe=rand(5,1);
lat=rand(5,1);
gamma=rand(5,1);
phi=rand(5,1);
A(1)=1800;
A(2)=1400;
A(3)=600;
A(4)=300;
A(5)=300;
T(1)=108.4;
T(2)=96.8;
T(3)=85.2;
T(4)=73.6;
T(5)=62;
L(5)=32.188;
L(4)=26.598;
L(3)=21.008;
L(2)=15.418;
L(1)=9.828;
V1(1)=0.096;
V1(2)=0.19;
V1(3)=0.25;
V1(4)=0.31;
V1(5)=1.46;
ho=9000;
hd=566;
hi=rand(5,1);
U=rand(5,1);
for i=1:5
V(i)=5.6;
x(i)=37.8*0.13/L(i);
cp(i)=4.19-2.35*x(i);
bpe(i)=1.78*x(i)+6.22*(x(i)^2);
lat(i)=2823.2-4.9783*T(i);
gamma(i)=L(i)/4;
end
phi(1)=V0*lat0/A(1);
phi(2)=(V(1)*lat(1))/A(2);
phi(3)=(V(2)*lat(2))/A(3);
phi(4)=(V(3)*lat(3))/A(4);
phi(5)=(V(4)*lat(4))/A(5);
for i=1:5
hi(i)=218+24*phi(i)-37*100*x(i)+1090*gamma(i)+32*(T(i)+bpe(i));
U(i)=((1/hi(i))+(1/ho)+1/hd)^-1;
end
f=rand(15,1);
j=rand(15,15);
z=rand(15,1);
z(1:15,1)=1;
count=0;
for i=1:3
f(1)=(V0*lat0+L(2)*cp(2)*(T(2)+bpe(2))-(L(2)-L(1))*(lat(1)+cp(1)*T(1))-L(1)*cp(1)*(T(1)+bpe(1)))*1000;
f(2)=U(1)*A(1)*(T0-T(1))-V0*lat0*1000;
f(3)=((L(2)-L(1)-V1(1))*lat(1)+L(3)*cp(3)*(T(3)+bpe(3))-(L(3)-L(2))*(lat(2)+cp(2)*T(2))-L(2)*cp(2)*(T(2)+bpe(2)))*1000;
f(4)=U(2)*A(2)*(T(1)-T(2))-(L(2)-L(1)-V1(1))*lat(1)*1000;
f(5)=((L(3)-L(2)-V1(2))*lat(2)+L(4)*cp(4)*(T(4)+bpe(4))-(L(4)-L(3))*(lat(3)+cp(3)*T(3))-L(3)*cp(3)*(T(3)+bpe(3)))*1000;
f(6)=U(3)*A(3)*(T(2)-T(3))-(L(3)-L(2)-V1(2))*lat(2)*1000;
f(7)=((L(4)-L(3)-V1(3))*lat(3)+L(5)*cp(5)*(T(5)+bpe(5))-(L(5)-L(4))*(lat(4)+cp(4)*T(4))-L(4)*cp(4)*(T(4)+bpe(4)))*1000;
f(8)=U(4)*A(4)*(T(3)-T(4))-(L(4)-L(3)-V1(3))*lat(3)*1000;
f(9)=((L(5)-L(4)-V1(4))*lat(4)+F*cpf*Tf-(F-L(5))*(cp(5)*T(5)+lat(5))-L(5)*cp(5)*(T(5)+bpe(5)))*1000;
f(10)=U(5)*A(5)*(T(4)-T(5))-(L(5)-L(4)-V1(4))*lat(4)*1000;
f(11)=(V1(5)*lat(5)-3670.85)*1000;
f(12)=(V1(4)*lat(4)-L(5)*cp(5)*(T(4)-5-(T(5)+bpe(5))))*1000;
f(13)=(V1(3)*lat(3)-L(4)*cp(4)*(T(3)-5-(T(4)+bpe(4))))*1000;
f(14)=(V1(2)*lat(2)-L(3)*cp(3)*(T(2)-5-(T(3)+bpe(3))))*1000;
f(15)=(V1(1)*lat(1)-L(2)*cp(2)*(T(1)-5-(T(2)+bpe(2))))*1000;
j(1,1)=lat0*1000; j(1,2)=(-(L(2)-L(1))*cp(1)-L(1)*cp(1))*1000; j(1,3)=L(2)*cp(2)*1000; j(1,4)=0; j(1,5)=0;
j(1,6)=((lat(1)+cp(1)*T(1))-cp(1)*(T(1)+bpe(1)))*1000; j(1,7)=(cp(2)*(T(2)+bpe(2))-(lat(1)+cp(1)*T(1)))*1000; j(1,8)=0; j(1,9)=0; j(1,10)=0;
j(1,11)=0;j(1,12)=0;j(1,13)=0;j(1,14)=0;j(1,15)=0;
j(2,1)=-lat0*1000; j(2,2)=-U(1)*A(1); j(2,3)=0; j(2,4)=0; j(2,5)=0; j(2,6)=0; j(2,7)=0; j(2,8)=0; j(2,9)=0; j(2,10)=0;j(2,11)=0;j(2,12)=0;j(2,13)=0;
j(2,14)=0;j(2,15)=0;
j(3,1)=0; j(3,2)=0; j(3,3)=(-(L(3)-L(2))*cp(2)-L(2)*cp(2))*1000; j(3,4)=L(3)*cp(3)*1000; j(3,5)=0; j(3,6)=-lat(1)*1000;
j(3,7)=(lat(1)+lat(2)+cp(2)*T(2)-cp(2)*(T(2)+bpe(2)))*1000; j(3,8)=(cp(3)*(T(3)+bpe(3))-(lat(2)+cp(2)*T(2)))*1000; j(3,9)=0; j(3,10)=0;
j(3,11)=-lat(1)*1000;j(3,12:15)=0;
j(4,1)=0; j(4,2)=U(2)*A(2); j(4,3)=-U(2)*A(2); j(4,4)=0; j(4,5)=0; j(4,6)=lat(1)*1000; j(4,7)=-lat(1)*1000; j(4,8)=0; j(4,9)=0; j(4,10)=0;
j(4,11)=lat(1)*1000;j(4,12:15)=0;
j(5,1)=0; j(5,2)=0;j(5,3)=0; j(5,4)=(-(L(4)-L(3))*cp(3)-L(3)*cp(3))*1000; j(5,5)=L(4)*cp(4)*1000; j(5,6)=0;
j(5,7)=-lat(2)*1000; j(5,8)=(lat(2)+lat(3)+cp(3)*T(3)-cp(3)*(T(3)+bpe(3)))*1000; j(5,9)=(cp(4)*(T(4)+bpe(4))-(lat(3)+cp(3)*T(3)))*1000; j(5,10)=0;
j(5,11)=0;j(5,12)=-lat(2)*1000; j(5,13:15)=0;
j(6,1)=0; j(6,2)=0; j(6,3)=U(3)*A(3); j(6,4)=-U(3)*A(3); j(6,5)=0; j(6,6)=0; j(6,7)=lat(2)*1000; j(6,8)=-lat(2)*1000; j(6,9)=0; j(6,10)=0;
j(6,11)=0; j(6,12)=lat(2)*1000;j(6,13:15)=0;
j(7,1)=0; j(7,2)=0; j(7,3)=0; j(7,4)=0; j(7,5)=(-(L(5)-L(4))*cp(4)-L(4)*cp(4))*1000; j(7,6)= 0; j(7,7)=0;
j(7,8)=-lat(3)*1000;j(7,9)=(lat(3)+lat(4)+cp(4)*T(4)-cp(4)*(T(4)+bpe(4)))*1000;j(7,10)=(cp(5)*(T(5)+bpe(5))-(lat(4)+cp(4)*T(4)))*1000;j(7,11)=0;
j(7,12)=0; j(7,13)=-lat(3)*1000; j(7,14)=0; j(7,15)=0;
j(8,1)=0; j(8,2)=0; j(8,3)=0; j(8,4)=U(4)*A(4); j(8,5)=-U(4)*A(4); j(8,6)=0; j(8,7)=0; j(8,8)=lat(3)*1000; j(8,9)=-lat(3)*1000; j(8,10)=0;j(8,11)=0;
j(8,12)=0;j(8,13)=lat(3)*1000;j(8,14)=0;j(8,15)=0;
j(9,1)=0; j(9,2)=0; j(9,3)=0; j(9,4)=0; j(9,5)=0; j(9,6)=0; j(9,7)=0; j(9,8)=0;
j(9,9)=-lat(4)*1000; j(9,10)=(lat(4)+cp(5)*T(5)+lat(5)-cp(5)*(T(5)+bpe(5)))*1000;j(9,11:13)=0; j(9,14)=-lat(4)*1000;j(9,15)=0;
j(10,1)=0; j(10,2)=0; j(10,3)=0; j(10,4)=0; j(10,5)=U(5)*A(5); j(10,6)=0; j(10,7)=0; j(10,8)=0; j(10,9)=lat(4)*1000; j(10,10)=-lat(4)*1000;
j(10,11:13)=0;j(10,14)=lat(4)*1000;j(10,15)=0;
j(11,1:14)=0;j(11,15)=lat(5)*1000;
j(12,1:4)=0; j(12,5)=-L(5)*cp(5)*1000;j(12,6:9)=0; j(12,10)=-cp(5)*(T(4)-5-(T(5)+bpe(5)))*1000;j(12,11:13)=0; j(12,14)=lat(4)*1000;j(12,15)=0;
j(13,1:3)=0; j(13,4)=-L(4)*cp(4)*1000;j(13,5)=L(4)*cp(4)*1000;j(13,6:8)=0; j(13,9)=-cp(4)*(T(3)-5-(T(4)+bpe(4)))*1000;j(13,10)=0;j(13,11:12)=0;
j(13,13)=lat(3)*1000;j(13,14:15)=0;
j(14,1:2)=0; j(14,3)=-L(3)*cp(3)*1000; j(14,4)=L(3)*cp(3)*1000; j(14,5:7)=0; j(14,8)=-cp(3)*(T(2)-5-(T(3)+bpe(3)))*1000; j(14,9:11)=0;j(14,12)=lat(2)*1000;
j(14,13:15)=0;
j(15,1)=0; j(15,2)=-L(2)*cp(2)*1000; j(15,3)=L(2)*cp(2)*1000;j(15,4:6)=0; j(15,7)=-cp(2)*(T(1)-5-(T(2)+bpe(2)))*1000;j(15,8:10)=0;
j(15,11)=lat(1)*1000;j(15,12:15)=0;
z=-inv(j)*f;
V0=0.1*V0+0.5*z(1);
T(1)=T(1)+z(2);
T(2)=T(2)+z(3);
T(3)=T(3)+z(4);
T(4)=T(4)+z(5);
L(1)=L(1)+z(6);
L(2)=L(2)+z(7);
L(3)=L(3)+z(8);
L(4)=L(4)+z(9);
L(5)=L(5)+z(10);
V1(1)=V1(1)+z(11);
V1(2)=V1(2)+z(12);
V1(3)=V1(3)+z(13);
V1(4)=V1(4)+z(14);
V1(5)=V1(5)+z(15);
V(1)=L(2)-L(1);
V(2)=L(3)-L(2);
V(3)=L(4)-L(3);
V(4)=L(5)-L(4);
V(5)=F-L(5);
x(i)=37.8*0.13/L(i);
cp(i)=4.19-2.35*x(i);
bpe(i)=1.78*x(i)+6.22*(x(i)^2);
lat(i)=2823.2-4.9783*T(i);
gamma(i)=L(i)/4;
phi(1)=V0*lat0/A(1);
phi(2)=(V(1)*lat(1))/A(2);
phi(3)=(V(2)*lat(2))/A(3);
phi(4)=(V(3)*lat(3))/A(4);
phi(5)=(V(4)*lat(4))/A(5);
fori=1:5;
hi(i)=218+24*phi(i)-37*100*x(i)+1090*gamma(i)+32*(T(i)+bpe(i));
U(i)=((1/hi(i))+(1/ho)+1/hd)^-1;
end

답변 (1개)

Alan Moses
Alan Moses 2021년 7월 1일
Some variables in your code are not updated in every iteration. For example, the variable gamma depends on L. L is upated every iteration, but gamma is not updated every iteration element-wise.
Refer this video on vectorizing code in MATLAB to avoid looping through an array and doing the operations on the matrix level. You may also refer to the post here that explains vectorization.

카테고리

Help CenterFile Exchange에서 Import, Export, and Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by