How can I fix this error?

조회 수: 9 (최근 30일)
asli eylul sert
asli eylul sert 2021년 6월 5일
댓글: asli eylul sert 2021년 6월 5일
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
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
asli eylul sert
asli eylul sert 2021년 6월 5일
When I run this code it gives me K and S values only for my last T value. It evaluates it in the Command Window but I only see one value for K and S in the Workspace. Any hint on how to correct it?

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
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
Walter Roberson
Walter Roberson 2021년 6월 5일
S = arrayfun(@(X)vpasolve(X,[0 1]), eqn, 'uniform', 0)
asli eylul sert
asli eylul sert 2021년 6월 5일
Thank you so much.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numeric Solvers에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by