How to solve for three answers from 3 equations using fsolve
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jcy Juice
am 13 Mai 2022
Kommentiert: Torsten
am 15 Mai 2022
I have three equations:
I've attempted to solve them but i am unsure where i am going wromg
%function file
function n = moles(guess)
global NC NH NO NCH4 NCO NCO2 NH2 NH2O
mol1 = guess(1); mol2 = guess(2); mol3 = guess(3);
%equations
n(1) = NCH4 + NCO + NCO2 - NC;
n(2) = NCH4 + NH2 + NH2O - NH;
n(3) = NCO + 2*NCO2 + NH2;
end
%mainfile
%inputs
NC = 10;
NH = 50;
NO = 5
sol = fsolve('assignment1',guess);
1 Kommentar
Akzeptierte Antwort
Davide Masiello
am 13 Mai 2022
Below, see an example of how to solve the system.
I had to make up the values of the constants since you have not specified them in your question.
clear,clc
% Constants (I made up the values)
molC = 1;
molH = 1;
molO = 1;
T = 600;
molCH4 = 1;
molCO = 1;
molCO2 = 1;
molH2 = 1;
molH2O = 1;
k1 = 1;
k2 = 1;
P = 1;
Po = 1;
% Initial guess
nguess = [2 1 1 3 2];
% Solver
sln = fsolve(@(x)moles(x,molC,molH,molO,T,k1,k2,molCH4,molCO,molCO2,molH2,molH2O,P,Po),nguess)
% Function
function n = moles(n,molC,molH,molO,T,k1,k2,molCH4,molCO,molCO2,molH2,molH2O,P,Po)
f = [ -n(1) + molCH4 + molCO + molCO2 - molC;...
-n(2) + 4*molCH4 + 2*molH2 + 2*molH2O - molH;...
-n(3) + molCO + 2*molCO2 + molH2;...
-n(4) + 3*log(molH2) + log(molCO) - log(molH2O) - log(molCH4) - log(k1);...
-n(5) + log(molH2) + log(molCO2) - log(molH2O) - log(molCO) - log(k2)
];
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Periodic Waveform Generation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!