how to use fsolve for non linear functions with some equations are the same form?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
Matt J
2023-3-2
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)
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
采纳的回答
Torsten
2023-3-2
移动:Torsten
2023-3-2
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 个评论
Torsten
2023-3-2
编辑:Torsten
2023-3-2
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".
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!