2
$\begingroup$

If you run my calculations given below

x[r_] = Integrate[1/(1 - 1/r - (r/4)^2), r] // Normal

Sol = NSolve[16 - 16 x + x^3 == 0, x, WorkingPrecision -> 100];
R1 = First[Sort[x /. Sol, Smaller]]
R2 = Sort[x /. Sol, Smaller][[2]]
R3 = Sort[x /. Sol, Smaller][[3]]

V = Simplify[(1 -a/r-b*r^2)*((l*(1 + l))/r^2 + (a/r^2 - 2*b*r)/r) /. {a -> 1, 
b -> 1/16} /. l -> 1];
ndvar = -16 ((Log[r - R1] R1)/(-16 + 3 R1^2) + (
Log[r - R2] R2)/(-16 + 3 R2^2) + (Log[R3 - r] R3)/(-16 + 3 R3^2));

fV[z_?NumericQ] :=If[Abs[z] <= 400,Re[V /. FindRoot[ndvar == z, {r,11/10`100}, 
AccuracyGoal -> Infinity, MaxIterations -> 10000,PrecisionGoal -> 100, 
WorkingPrecision -> 100]], 0];

Plot[fV[x], {x, -50, 50}, PlotRange -> All,AxesLabel -> {"v - u", "V"},
  ImageSize -> Large, LabelStyle -> {Black, Bold, Medium}]

you will find a FindRoot error at the end which I could not remove it by using help center. How can I remove it? I will be thankful if someone help.

$\endgroup$
2
  • 2
    $\begingroup$ Do you want to fix the error or suppress the message ? Off[General::precw] will suppress it. $\endgroup$
    – Lotus
    Jul 24 '18 at 9:08
  • $\begingroup$ Yeah, in this case the error is actually only a warning. It can suppressed without worries. $\endgroup$ Jul 24 '18 at 9:09
4
$\begingroup$

Henrik Schumacher's answer gets you half way there. The other half of the problem is that the Plot iterator is machine precision. You can correct this by expressly applying SetPrecision:

Plot[fV[SetPrecision[x, 100]], {x, -50, 50}
 , PlotRange -> All
 , AxesLabel -> {"v - u", "V"}
 , ImageSize -> Large
 , LabelStyle -> {Black, Bold, Medium}
]

This is needed to work around a bug: Precision of computations done by Plot

$\endgroup$
8
  • $\begingroup$ Thanks a lot. Do you have a suggestion to remove errors at the end of sol = NDSolveValue[{-4*D[S[u, v], u, v] == fV[v - u]*S[u, v], S[u, 0] == Exp[-(-vc)^2/(2*sigma^2)], S[0, v] == Exp[-(v - vc)^2/(2*sigma^2)]} /. {vc -> 10, sigma -> 3}, S, {u, 120, 210}, {v, 120, 210}, MaxStepSize -> 1]. This equation comes after the code given in my question. $\endgroup$
    – Mehrab
    Jul 24 '18 at 9:50
  • $\begingroup$ Oh my. I forgot about that... (+1) $\endgroup$ Jul 24 '18 at 10:14
  • $\begingroup$ @Henrik -- You also have my +1 of course. Any ideas re: the comment above? $\endgroup$
    – Mr.Wizard
    Jul 24 '18 at 10:19
  • 1
    $\begingroup$ @Mehrab For further numerical computstions, it might be worthwhile to redefine fV as follows: fV[z0_?NumericQ] := With[{z = SetPrecision[z0, prec + 1]}, If[Abs[z] <= 400, Re[V /. FindRoot[ ndvar == z, {r, 11/10}, MaxIterations -> 10000, WorkingPrecision -> prec ] ], 0 ] ];. But also not that it is rather pointless use such high (working-)precision functions within NDSolve: You will usually only obtain a few digits precision for the solution, in particular with the humongous step sizes. $\endgroup$ Jul 24 '18 at 11:25
  • $\begingroup$ @HenrikSchumacher Thanks a lot, but what is prec? $\endgroup$
    – Mehrab
    Jul 24 '18 at 11:30
4
$\begingroup$

NSolve loses a bit of precision (less than a digit). Grant it some extra digits with

Sol = NSolve[16 - 16 x + x^3 == 0, x, WorkingPrecision -> 110];

and it should wotk fine.

$\endgroup$
0
$\begingroup$

If you restrict your final parameterrange to -40<x<40 you can get an easy straightforward solution (without setting Precsision)

sol[z_?NumericQ] :=V /.  NSolve[{ndvar == z, R2 < r < R3}, r, Reals][[1]]
Plot[sol[x], {x, -40, 40}, PlotRange -> All]

enter image description here

$\endgroup$

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.