How can I fix this error?

10 Ansichten (letzte 30 Tage)
asli eylul sert
asli eylul sert am 5 Jun. 2021
Kommentiert: asli eylul sert am 5 Jun. 2021
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 Kommentare
Houssem
Houssem am 5 Jun. 2021
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 am 5 Jun. 2021
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?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by