# MATLAB: Nonlinear equation solver issue

fsolvenonlinear

Hello, I have an equation
N = (DP/RT * ln(P/(P-P*)))/(L/A) + (l/a))
P,R,T,P*,(L+l), and A are known. L+l is always .05
There is some experimental data
l = .004, N = 6.6e-11
l = .008, N = 4.9e-11
l = .012, N = 4.0e-11
I am trying to find D and a. So I make a function and I try to use fsolve, but when I do I just get an erroneous answer. I am saying D(1) = D, and D(2) = a in my function
function F = stefanflow(D)P = 1e5;T = 294;R = 8.314e3;A = 1e-4;P_sat = 1.12e4;O = log(P/(P-P_sat));I = P/(R*T);F = zeros(3,1);F(1) = 6.6e-11 - (D(1)*I*O)/(((.05-.004)/A)+(.004/D(2)));F(2) = 4.9e-11 - (D(1)*I*O)/(((.05-.008)/A)+(.008/D(2)));F(3) = 4.0e-11 - (D(1)*I*O)/(((.05-.012)/A)+(.012/D(2)));
I run this in my script file
options = optimoptions('fsolve','Display','iter');[D,fval] = fsolve(@stefanflow,[1e-5;1e-5],options);
And this is my output
Warning: Trust-region-dogleg algorithm of FSOLVE cannot handlenon-square systems; using Levenberg-Marquardt algorithm instead. > In fsolve at 286                                           First-Order                    Norm of    Iteration  Func-count    Residual       optimality      Lambda           step       0           3     2.59598e-22        1.19e-16         0.01       1           6     2.59598e-22        1.19e-16        0.001    1.37935e-14Equation solved, fsolve stalled.fsolve stopped because the relative size of the current step is less than thedefault value of the step size tolerance and the vector of function valuesis near zero as measured by the default value of the function tolerance.<stopping criteria details>EDU>> DD =     1.0e-04 *      0.1000      0.1000
What is going on, and how can I solve this system?

>> stefanflow(D)    ans =       1.0e-11 *        0.9493        0.9167        0.9243
   options = optimoptions('fsolve','Display','iter','TolFun',1e-30,'TolX',1e-30);
    D =       1.0e-04 *        0.1013        0.1391