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$
  • $\begingroup$ Welcome! I suggest the following: 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 faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – user9660 Aug 11 '16 at 18:35
  • 1
    $\begingroup$ Could you give Mathematica code for your definition of x[\[Phi]]? Could be similar to this question. $\endgroup$ – Chris K Aug 11 '16 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$ – Michael Seifert Aug 11 '16 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$ – Chertan Aug 11 '16 at 19:04
  • $\begingroup$ @MichaelSeifert yes, I need negative one. Therefore I used the restrictions on phi in the first example $\endgroup$ – Chertan Aug 11 '16 at 19:07
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

| improve this answer | |
$\endgroup$
  • $\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$ – Chertan Aug 12 '16 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$ – Chris K Aug 13 '16 at 1:39
  • $\begingroup$ yes, that's exactly what I meant. Thank you! $\endgroup$ – Chertan Aug 13 '16 at 13:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.