Error using plot Vectors must be the same length. [line 29 ERROR]

1 Ansicht (letzte 30 Tage)
Matthew Wheeler
Matthew Wheeler am 23 Jan. 2023
Bearbeitet: Walter Roberson am 23 Jan. 2023
function moleFractionA = antonie2molfraction(A,B,T,P);
A = [6.80896, 935.86, 238.73]; %1x3 array A is n-butane
B = [6.87024, 1168.72, 224.21]; %1x3 array B is n-hexane
T = [0:10:1000]; %celsius
P = 1125.09; %torr ~ 1.5 bar
PvaporA = zeros(1,11);
PvaporB = zeros(1,11);
liquidmoleFractionA = zeros(1,11);
vapormoleFractionA = zeros(1,11);
for i = 1:11
PvaporA(i) = 10 ^ (A(1)-(A(2)/(A(3)+T(i))));
PvaporB(i) = 10 ^ (B(1)-(B(2)/(B(3)+T(i))));
liquidmoleFractionA(i) = (P-PvaporB(i)) ./ (PvaporA(i)-PvaporB(i));
vapormoleFractionA(i) = PvaporA(i) .* liquidmoleFractionA(i) / P;
end
plot(liquidmoleFractionA, T)
hold on
plot(vapormoleFractionA, T)
hold off
xlabel('Mole Fraction of N-Butane')
ylabel('Temperature in Celsius')
title('N-Butane / N-Hexane TXY Diagram')
end
  1 Kommentar
Torsten
Torsten am 23 Jan. 2023
Bearbeitet: Torsten am 23 Jan. 2023
PvaporA(i) = 10 ^ (A(1)-(A(2)/(A(3)+T(i))));
PvaporB(i) = 10 ^ (B(1)-(B(2)/(B(3)+T(i))));
And you are sure the temperature is in degreeC and the vapor pressure calculated is in torr ?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jim Riggs
Jim Riggs am 23 Jan. 2023
Bearbeitet: Jim Riggs am 23 Jan. 2023
The two arguments to the 'plot' command must be the same size, e.g. 'liquidmoleFractionA' must have the same length as 'T'.
A good way to do this is to use the 'T' vector length to define the loop parameter;
npt = length(T)
PvaporA = zeros(1,npt);
... etc.
for i=1:npt
PvaporA(i) = 10 ^ (A(1)-(A(2)/(A(3)+T(i))));
... etc.
Now you simply define the vector 'T', and all of your other vectors will conform to it.

Community Treasure Hunt

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

Start Hunting!

Translated by