How can I fix this error?
10 ビュー (過去 30 日間)
古いコメントを表示
Hello, I want to find a ksi value for the K values I obtained from the T values, but when I run the code even though my K values are there vpasolve gives me this message: "Empty sym: 0-by-1" I would really appreciate if you can guide me. Thanks.
clc;
clear;
nN2 = 1; %starting mol
nH2 = 3; %starting mol
nNH3 = 0; %starting mol
R = 8.314;%J/molK
deltaGstd = -33; %kJ/mol
deltaHstd = -92.2; %kJ/mol
deltaSstd = -0.1987; %(deltaGstd - deltaHstd)/(-T)
syms ksi
T = 298:1:434; %T values
K = exp(((-1).*deltaHstd.*1000 + T.*deltaSstd.*1000)./(R.*T)) %K values
eqn =((4.*ksi.^2)./((4-2.*ksi).^2))./(((1-ksi)./(4-2.*ksi)).*(((3-3.*ksi)./(4-2.*ksi)).^3))==K
S = vpasolve(eqn,ksi)
3 件のコメント
Houssem
2021 年 6 月 5 日
I think you can make a loop on T
Pleas try this code
clc;
clear;
nN2 = 1; %starting mol
nH2 = 3; %starting mol
nNH3 = 0; %starting mol
R = 8.314;%J/molK
deltaGstd = -33; %kJ/mol
deltaHstd = -92.2; %kJ/mol
deltaSstd = -0.1987; %(deltaGstd - deltaHstd)/(-T)
syms ksi
for T = 298:1:434; %T values
K = exp(((-1).*deltaHstd.*1000 + T.*deltaSstd.*1000)./(R.*T)); %K values
eqn =((4.*ksi.^2)./((4-2.*ksi).^2))./(((1-ksi)./(4-2.*ksi)).*(((3-3.*ksi)./(4-2.*ksi)).^3))==K;
S = vpasolve(eqn,ksi)
end
採用された回答
Walter Roberson
2021 年 6 月 5 日
Your T is a vector which leads to eqn being a vector. When you vpasolve a vector, it tries to find a combination of variables that solves all of the elements simultaneously. solve() and vpasolve() are simultaneous equation solvers, not solvers of each equation independently.
Houssem is correct that one way of solving this problem is to loop over the T values. The particular way that they looped does not store the individual results, but it is certainly possible to modify the code slightly to store the values.
Another approach is not to loop, to allow the vector eqn to be created, but then to use
S = arrayfun(@vpasolve, eqn, 'uniform', 0)
This will produce a cell array of outputs. I recommend a cell array output unless you are certain that mathematically there will definitely be a solution for each entry.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!