how to use fsolve for non linear functions with some equations are the same form?

6 views (last 30 days)
Dear MATLAB expert,
I was trying to solve non linear equations using fsolve. I get one extra equation from the other other equations to make the number of equations equal with the unkowns. The codes and problem description looks like as shown below.
function F = partitionFirst(C_entrance_MS,C_surf,Z,phi)
k=C_entrance_MS(1); %concentration inside the membrane inlet
l=C_entrance_MS(2);
m=C_entrance_MS(3);
X_mem=C_entrance_MS(4);
Z_AA=0.08;
Z_Na=1;
Z_Cl=-1;
C_surf(1)= 7.81328;C_surf(2)=4.07924;C_surf(3)=7.265;
phi_1=0.64;
phi_2=0.9897;
phi_3=0.98144;
F(1)= k*Z_AA + X_mem + Z_Na*phi_2*C_surf(2)*(k/(phi_1*C_surf(1)))^(Z_Na/Z_AA) + Z_Cl*phi_3*C_surf(3)*(k/(phi_1*C_surf(1)))^(Z_Cl/Z_AA);
F(2)= -l + phi_2*C_surf(2)*(k/(phi_1*C_surf(1)))^(Z_Na/Z_AA);
F(3)= -m + phi_3*C_surf(3)*(k/(phi_1*C_surf(1)))^(Z_Cl/Z_AA);
F(4)= k*Z_AA + Z_Na*l + Z_Cl*m + X_mem;
end
F(1) is extra equation that have similarity with F(4). Because if you substitue 'l' and 'm' using equations F(2) and F(3) to equation F(4), you will find equation F(1). That means if I take equation F(1) and F(4) as one same equation, I will have three equations together with F(2) and F(3). But I have four variables to solve, that are k,l,m and X_mem. fsolve solved the equation. But I don't know if solving four unknowns with three equations is possible? of If F(1) and F(4) can be considered as two different functions? How is that possible for the solver to solve this unkowns from three equation and one rearranged equation? Can you please explain this to me?
Below is the way I solved the equations
z=[1 1 1 1]
C_entrance_MS=fsolve(@partitionFirst,z)
Thank you very much in advance!!!
  2 Comments
Matt J
Matt J on 2 Mar 2023
Below is the way I solved the equations
That doesn't work (for obvious reasons).
z=[1 1 1 1];
C_entrance=fsolve(@partitionbyX_mem,z)
Unrecognized function or variable 'partitionbyX_mem'.

Error in fsolve (line 264)
fuser = feval(funfcn{3},x,varargin{:});
function F = partitionFirst(C_entrance_MS,C_surf,Z,phi)
k=C_entrance_MS(1); %concentration inside the membrane inlet
l=C_entrance_MS(2);
m=C_entrance_MS(3);
X_mem=C_entrance_MS(4);
Z_AA=0.08;
Z_Na=1;
Z_Cl=-1;
C_surf(1)= 7.81328;C_surf(2)=4.07924;C_surf(3)=7.265;
phi_1=0.64;
phi_2=0.9897;
phi_3=0.98144;
F(1)= k*Z_AA + X_mem + Z_Na*phi_2*C_surf(2)*(k/(phi_1*C_surf(1)))^(Z_Na/Z_AA) + Z_Cl*phi_3*C_surf(3)*(k/(phi_1*C_surf(1)))^(Z_Cl/Z_AA);
F(2)= -l + phi_2*C_surf(2)*(k/(phi_1*C_surf(1)))^(Z_Na/Z_AA);
F(3)= -m + phi_3*C_surf(3)*(k/(phi_1*C_surf(1)))^(Z_Cl/Z_AA);
F(4)= k*Z_AA + Z_Na*l + Z_Cl*m + X_mem;
end
Tadele
Tadele on 2 Mar 2023
Dear Matt,
I edited my question. I just copied the call function from one of many of my scriptes. Sorry for the invonvenience.
Can you please chech that again, if it works?

Sign in to comment.

Accepted Answer

Torsten
Torsten on 2 Mar 2023
Moved: Torsten on 2 Mar 2023
You can solve systems with more unknowns than equations, but in most cases ( as in yours ), the solution will not be unique.
The solution for your system is
k = an arbitrary value
l = phi_2*C_surf(2)*(k/(phi_1*C_surf(1)))^(Z_Na/Z_AA)
m = phi_3*C_surf(3)*(k/(phi_1*C_surf(1)))^(Z_Cl/Z_AA)
X_mem = -(k*ZAA + Z_na*l + Z_Cl*m)
  4 Comments
Tadele
Tadele on 2 Mar 2023
Okay, tthank you, that is clear.
One thing I still don't get is, why fsolve then solves for four variables itself since I only give initial values and not the arbitrary value for X_mem. Does fsolve give arbitrary value as a solution? As can be seen from the codes, when I give initial values z = [1 1 1 1] and use fsolve, I get four outputs.
Torsten
Torsten on 2 Mar 2023
Edited: Torsten on 2 Mar 2023
Does fsolve give arbitrary value as a solution?
Yes. Most probably a solution that is next to the initial values. Try another initial guess vector and see if the solution changes.
Usually "fsolve" should detect that a system of equations is underdetermined (more variables than independent equations as in your case). The error message would be "Singular Jacobian detected".

Sign in to comment.

More Answers (0)

Categories

Find more on Systems of Nonlinear Equations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!