Message Boards Message Boards

How to fix the machine precision warning?

Posted 2 years ago

Hi, i am trying to plot a function but it is showing me warning. Here is my code

ClearAll["Global`*"];
\[Lambda] = 1;
\[Beta] = ArcSin[\[Lambda]/Sqrt[1 + \[Lambda]^2] ];
T[F_, \[Epsilon]_] := 
  8 (1 + \[Epsilon]^2/
     12) (1 /4 (1 - r^2) + \[Epsilon] 1 /
      8 (r^3 - 
        r) Sin[\[Zeta]] + \[Epsilon]^2 (1 /
         24 Cos[2 \[Zeta]] (r^4 - r^2) + (r^2/16 - r^4/32 - 1/
          32)) + \[Epsilon]^3 1 /
      32 Sin[\[Zeta]] (r^5 - r^3) + \[Epsilon]^3 1/
      72 F \[Lambda] Cos[\[Beta]] Sin[
       2 \[Zeta]] (r^2 - r^4) + \[Epsilon]^3 1/
      64  Sin[3 \[Zeta]] (r^3 - r^5));
Plot[
 {FindMaxValue[T[F, 0.1], {r, \[Zeta]}], 
  FindMaxValue[T[F, 0.2], {r, \[Zeta]}], 
  FindMaxValue[T[F, 0.3], {r, \[Zeta]}], 
  FindMaxValue[T[F, 0.4], {r, \[Zeta]}]}, {F, -200, 200},
 PlotRange -> {Automatic, {1.996, 2.020}},
 AxesOrigin -> {Automatic, Automatic},
 AxesStyle -> {Black, Black},
 AxesLabel -> {F, Subscript[
\!\(\*OverscriptBox[\(T\), \(~\)]\), max]},
 LabelStyle -> {FontFamily -> "Times New Roman", 20, Bold},
 PlotLegends -> 
  Placed[{TraditionalForm["\[Epsilon]=0.1"], 
    TraditionalForm["\[Epsilon]=0.2"], 
    TraditionalForm["\[Epsilon]=0.3"], 
    TraditionalForm["\[Epsilon]=0.4"]}, {Right, Top}],
 PlotStyle -> {{Blue, Thick}, {Black, Thick}, {Red, Thick}, {Green, 
    Thick}},
 ImageSize -> Large
 ]

The function behaving absurd as i am geting the warning as shown in attched file. How to add more precision to the function? enter image description here

POSTED BY: KRISHAN SHARMA
3 Replies
Posted 2 years ago

Hi Krishan,

If you look at T[-150, 0.4] you will see terms involving Sin and Cos which are bounded by (-1, 1) and terms involving powers of r. Looks like FindMaxValue gets lost increasing r in attempting to find the maximum. You can help it by providing starting values for the search. Using

FindMaxValue[T[F, 0.4], {{r, -0.08}, {\[Zeta], 1.6}}]

we get no messages and this plot

enter image description here

POSTED BY: Rohit Namjoshi
Posted 2 years ago

Thanks Rohit ji

POSTED BY: KRISHAN SHARMA

You can direct FindMaxValue to use higher precision by setting WorkingPrecision->30 (for example). But in order for that to work it must have input of equal or greater precision, so T[F, 0.1] would have to be something like T[F, 1/10] or T[F,N[1/10,30]]. But there is another hitch. Plot itself will use machine values for F. So you would need to also set the WorkingPrecision option of Plot to match that of FindMaxValue.

Whether or how well this might work will depend on how well FindMaxValue performs at the higher precision.

POSTED BY: Daniel Lichtblau
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract