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

1 回表示 (過去 30 日間)
Matthew Wheeler
Matthew Wheeler 2023 年 1 月 23 日
編集済み: Walter Roberson 2023 年 1 月 23 日
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 件のコメント
Torsten
Torsten 2023 年 1 月 23 日
編集済み: Torsten 2023 年 1 月 23 日
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 ?

サインインしてコメントする。

回答 (1 件)

Jim Riggs
Jim Riggs 2023 年 1 月 23 日
編集済み: Jim Riggs 2023 年 1 月 23 日
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.

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by