1
$\begingroup$

I have the equation

$$ x(\phi)=\frac{1}{2\sqrt2}\left(\frac{-2}{\phi}+\log\left(\frac{1+\phi}{1-\phi}\right)\right) $$ I need to find the dependence $\phi(x)$, so I use NSolve:

B = 20;
NSteps = 2*B*100; 
H = N[2*B/NSteps];
X = Range[-B, B, H];
F[i_] := NSolve[x[ϕ] == i && (-1.0 <= ϕ <= 0.0), ϕ];
Monitor[PhiTable = Table[ϕ /. F[i], {i, -B, B, H}], i]

And I get this output:

Output

NSolve can't find the solution and it gives an empty result at the values from about -15 and lower. I suppose this bug is caused by exponential asymptotic of the function $\phi(x)$.

But when I write

F[i_] := NSolve[x[ϕ] == i, ϕ, Reals];
Monitor[PhiTable = Table[ϕ /. F[i][[1]], {i, -B, B, H}], i]

It finds roots at the begining but freezes at the point 16.44 and higher.

Is there a way to fix it? Or shall I use another function, not NSolve?

Added:

x[ϕ_] := 1/(2 Sqrt[2]) (-2/ϕ + Log[(1 + ϕ)/(1 - ϕ)]);
$\endgroup$
7
  • $\begingroup$ Welcome to Mathematica.SE! 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the help center! 3) When you see good questions and answers, vote them up by clicking the vote triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ Commented Aug 11, 2016 at 18:35
  • 1
    $\begingroup$ Could you give Mathematica code for your definition of x[\[Phi]]? Could be similar to this question. $\endgroup$ Commented Aug 11, 2016 at 18:55
  • $\begingroup$ It looks like your equation $x(\phi) = x_0$ has two solutions for all values of $x_0$, one with positive $\phi$ and one with negative $\phi$. Do you have a preference as to which one is returned? $\endgroup$ Commented Aug 11, 2016 at 19:03
  • $\begingroup$ @ChrisK definition: x[[Phi]_] := 1/(2 Sqrt[2]) (-2/[Phi] + Log[(1 + [Phi])/(1 - [Phi])]); I also added it to the post as screenshot $\endgroup$ Commented Aug 11, 2016 at 19:04
  • $\begingroup$ @MichaelSeifert yes, I need negative one. Therefore I used the restrictions on phi in the first example $\endgroup$ Commented Aug 11, 2016 at 19:07

1 Answer 1

1
$\begingroup$

The root tracker TrackRoot I wrote here can be applied to this problem. First, run TrackRoot from that link.

enter image description here

Then:

x[ϕ_] := 1/(2 Sqrt[2]) (-2/ϕ + Log[(1 + ϕ)/(1 - ϕ)]);
tr = TrackRoot[{x[ϕ] - xval}, {ϕ}, {xval, -20, 20}, 0, {-0.5}];
Plot[ϕ[x] /. tr, {x, -20, 20}]

enter image description here

$\endgroup$
3
  • $\begingroup$ Thanks a lot, it works! Is it possible to correct this function and not to use interpolation? I'd like to get only values of phi. Sorry if it is a very foolish and simple question, I have never worked with manual functions before. $\endgroup$ Commented Aug 12, 2016 at 14:22
  • $\begingroup$ @Chertan I'm not sure if this is exactly what you mean by correcting this function, but you can extract particular values of \[Phi] like this: \[Phi][1] /. tr gives -0.506903. $\endgroup$ Commented Aug 13, 2016 at 1:39
  • $\begingroup$ yes, that's exactly what I meant. Thank you! $\endgroup$ Commented Aug 13, 2016 at 13:42

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.