How can I fix this error?
2 次查看(过去 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.
3 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Equation Solving 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!