Help on solving 7 non linear equations with 7 unknows.

First time posting on this blog! Also not a guru in matlab! Any help is amazing!
Hello, this is a advanced thermal systems project where all values of n are the coefficients infront of a balanced stoichiometric equation and must be positive. I have attemped to solve these equations mutlple times using fsolve but it has either not converged, or congerged on the wrong value. Can anyone provide any insight to this or suggest any other root finder/ solving functions that may be more useful?
The system has seven equations all values are known except values of n. The problem needs to find the values of n which can be seen within the equations provided in the picture. The code has been run through muitiple diffrent ways. Fsolve seems to be the best way about solving these variables. could someone please help us out in the correct method for solving this problem it would be much appreciated. it has been a very long tedious process and we are getting no where within the code.
Also data has been pulled from an excel sheet which is also attached.
%ni=n1+n2+n3+n4+n5+n6+n7
%% Define constants
po=100; %kpa
p=50; %kpa contant pressure for products and reactants
Tr=298.15; % k reactants temp
Tp=4000; %k products temp
To=298.15; %standard state temp
R=8.314472; %universal gas constant
%% Imported state values for Reactants (B2H6,F2) and Products (BF,BF2,BF3,F,H2,H,HF)
%in order listed
%delta h
dhr=xlsread('ATSproject3.xlsx','C2:C3');
dhp=xlsread('ATSproject3.xlsx','C5:C11');
%ho
hor=xlsread('ATSproject3.xlsx','D2:D3');
hop=xlsread('ATSproject3.xlsx','D5:D11');
%so
sor=xlsread('ATSproject3.xlsx','E2:E11');
sop=xlsread('ATSproject3.xlsx','E5:E11');
%M molecular mass
Mr=xlsread('ATSproject3.xlsx','H2:H3');
Mp=xlsread('ATSproject3.xlsx','H5:H11');
%Cp (products only)
Cp=xlsread('ATSproject3.xlsx','G5:G11');
% go for products
g=zeros(1,length(dhp));
for i=1:length(dhp)
g(i)= (hop(i)+dhp(i))-(Tp*sop(i));
end
% Delta G for dissocation equations
dG1=-g(3)+g(2)+g(4);
dG2=-g(2)+g(1)+g(4);
dG3=-g(7)+g(6)+g(4);
dG4=-g(5)+2*g(6);
% K Values
K1=exp(-dG1/(R*Tp));
K2=exp(-dG2/(R*Tp));
K3=exp(-dG3/(R*Tp));
K4=exp(-dG4/(R*Tp));
% Moles of Reactants
nr=[1,6.55];
% Attempt 2 this should be working
f= @(n)[((n(2)*n(4))/n(3))*(p/po)*(1/(n(1)+n(2)+n(3)+n(4)+n(5)+n(6)+n(7)))-K1...
, ((n(1)*n(4))/n(2))*(p/po)*(1/(n(1)+n(2)+n(3)+n(4)+n(5)+n(6)+n(7)))-K2...
, ((n(6)*n(4))/n(7))*(p/po)*(1/(n(1)+n(2)+n(3)+n(4)+n(5)+n(6)+n(7)))-K3...
, ((n(6)^2)/n(5))*(p/po)*(1/(n(1)+n(2)+n(3)+n(4)+n(5)+n(6)+n(7)))-K4...
, n(1)+n(2)+n(3)-2 ...
, 2*n(2)+n(6)+n(7)-6 ...
, n(1)+2*n(2)+3*n(3)+n(4)+n(7)-(6.55*2)];
n0=[0.1,2,1,4,5,2,0.1]; %Initial guess
options=optimset('MaxIter',10^10,'MaxFunEvals',10^10);
[np,FVAL]=fsolve(f,n0,options);
% Check Mass Balance
mr=0;
mp=0;
for a= 1:length(Mr)
mr= mr+ Mr(a)*nr(a);
end
for j=1:length(Mp)
mp= mp+ Mp(j)*np(j);
end
Mass_Balance=mp-mr;
disp(num2str(Mass_Balance));

1 Comment

Hi,
sor=xlsread('ATSproject3.xlsx','E2:E11');
should be:
sor=xlsread('ATSproject3.xlsx','E2:E3');
and then the results will be as below:
n1: 0.465372978662155
n2: 1.2190908489085
n3: 0.315536172429156
n4: 6.3561076954786
n5: 0.00735092123602289
n6: 0.668089191427513
n7: 2.89372911075519
Feval:
7.1276318180935E-14
-8.91925422408235E-13
3.73524822183668E-12
2.22044604925031E-15
-1.89182003396127E-13
-2.96651592179842E-13
4.13891143580258E-13

Sign in to comment.

Answers (0)

Products

Release

R2020a

Asked:

on 14 Oct 2020

Edited:

on 15 Oct 2020

Community Treasure Hunt

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

Start Hunting!