Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
Matthew Wheeler
Matthew Wheeler le 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 commentaire
Torsten
Torsten le 23 Jan 2023
Modifié(e) : Torsten le 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 ?

Connectez-vous pour commenter.

Réponses (1)

Jim Riggs
Jim Riggs le 23 Jan 2023
Modifié(e) : Jim Riggs le 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