"David Garrido Lopez" <forolo86@hotmail.com> wrote in message <i6u3eu$8vs$1@fred.mathworks.com>...
> Hi,
>
> I am trying to solve a transcendental equation with fsolve and should be easy but I always end up with the same result, and I get the following warning:
> "Optimizer appears to be converging to a minimum that is not a root:
> Sum of squares of the function values is > sqrt(options.TolFun).
> Try again with a new starting point."
>
> My code is the following:
>
> function no(T)
> format long;
> %%%%%%% Definition of variables
> Nd = 1e17;
> Na = 5e16;
> K = 8.617343e5;
> Eg = 1.166  ((T*0.473e3)^2)/(T + 636);
> Nc = 2.8e19*(T/300)^(3/2);
> Nv = 1.04e19*(T/300)^(3/2);
> ni = sqrt(Nc*Nv)*exp(Eg/(K*T));
> mo = 9.11e31;
> me = 1.08*mo;
> mh = 0.81*mo;
> Ea = 45e3;
> Ed = Eg  44e3;
> h = 6.626e34;
>
> f=@(n) (Nd*0.5*exp(44e3/(K*T))*Nc)/(n + 0.5*exp(44e3/(K*T))*Nc)  Na*n/(n + 4*exp((45e3Eg)/(K*T))*Nc) + (ni^2)/n n;
> sol=fsolve(f, NdNa)
>
>
> The last two lines are the main code. Where f is my function and sol should be the solution. I know that the exact solution (or very close) at T=300 is NdNa, so that's why I use that as the initial guess. But then independing of T, the result is always the same (NdNa) which is wrong.
> I would really appreciate any help that helps me figure out what is going on and how can I solve that equation.
>
> Thanks,
>
> David.
       
Unless my eyes deceive me, that is not a transcendental equation in the unknown n. It can be reduced to a quartic polynomial equation in n which you can solve with matlab's 'roots' function, once you know the value of T and the various other variables. That suggests that you may have used an unwise initial estimate in fsolve which gets caught in a local minimum above zero, but why use fsolve at all in such a simple problem?
Roger Stafford
