thank you all for your suggestions.
They have been very helpful.
I concluded that by defining 2 functions, as in the following:
x0 = {x -> 1};
f1[a_?NumericQ] := {x0 = FindRoot[x == E^(-a x), {x, x0[[1, 2]]}]};
f2[a_] := x /. f1[a];
I can Plot[f2[a],{a,0,2}]
and obtain what I wanted.
Now, moving on to my real problem.
What I really want to do is to find the complex roots of some very complicated equations, involving generalized hypergeometric and the Meijer G functions.
So, I first tried to solve a simpler, well-known equation, which provides the dispersion relation of longitudinal (a.k.a. Langmuir) waves in thermal plasmas.
The code I wrote is the following:
================================================
ZF[z_] = I Sqrt[\[Pi]] E^-z^2 Erfc[-I z];
Zp[z_] = -2 (1 + z ZF[z]);
de[q_?NumericQ] := {z0 = FindRoot[2 q^2 - Zp[z/(Sqrt[2] q)], {z, z0[[1, 2]]}]};
drl1[q_] := z /. de[q];
drl2[q_?NumericQ] := FindRoot[2 q^2 - Zp[z/(Sqrt[2] q)], {z, 1}][[1, 2]];
================================================
The functions ZF[z]
and Zp[z]
evaluate the plasma dispersion (or Faddeeva) function and its derivative.
The function de[q]
implements the numerical solution of the dispersion equation.
The function drl1[q]
contains the dispersion relation, obtained with the "backsubstituting method" you helped me to implement.
The function drl2[q]
does the same, but the initial guess is fixed at z = 1
.
When I plotted the real part of both drl1[q] and drl2[q] I got the following outputs:
=======================================
Plot[Re[drl2[q]], {q, 0.01, 2}]
z0 = {z -> 1};
Plot[Re[drl1[q]], {q, 0.01, 2}]
========================================
As you can see I got mixed results. Comparing both plot you can easily guess the correct curve.
Now I guess that I either have an accuracy problem or I have to select and configure the appropriate method employed by FindRoot
.
When I implement the same type of root-finding code in a FORTRAN program I always use the previous solution as the initial guess for the next one. That's why I wanted to do the same with Mathematica. Unfortunately, it didn't quite work out...
I naively tried to increase the working precision:
==============================================
Plot[Re[drl2[q]], {q, 0.01, 2}, WorkingPrecision -> 48]
z0 = {z -> 1};
Plot[Re[drl1[q]], {q, 0.01, 2}, WorkingPrecision -> 48]
============================================
And it seems that the root-finder is jumping between 2 solutions.
Can you give me now some hint here? I confess that I'm not very savvy with Mathematica and don't really know which methods are implemented.
I've found a list in:
here.
Are those the methods I have at my disposal? Which one would be the best suited to find complex roots of transcendental functions?
In my FORTRAN codes I always use the Miller method because it's very simple and robust, but it seems that Mathematica does not support it.