2
$\begingroup$

I just recently updated from version 11.2 -> 12...there apparently are quite a few changes since 11.2. $\unicode{952}\unicode{960}$

One being how version >11.3 deal with numbers that approach zero.

To simulate a physical impulse one can use such an equation:

bump[t_] := 7 E^(-10 (t - 3)^2) - 3/2 E^(-10 (t - 6)^2) + 3 E^(-10 (t - 9)^2)

plot

Which looks like this plotted over time in 11.2 and 11.1 this didn't cause any issues for me, I use this function quite often for impulses in many systems.

Now however I am constantly getting an error that comes along with it:

error

After doing some duckduckgoing, I found in this post And with some more infos and what I thought would be a solution at this post

One can simply increase the precision using

Exp[-900`20]
(*3.6678745841776872*10^-348*)

However as I try in all combinations of adding the higher precision or using Working Precision -> 20 I get error messages, or barring error messages in the functions themselves, I get the old General error message in the plot,

errors

When using NDSolve[] the system becomes stiff at a specific time and cannot be further calculated (which in prior versions was again, never an issue)

Example working code from 11.2 with error from v12 and NDSolve:

Plot[{θ[t] 10, ϕ'[t]} /. 
   NDSolve[{{{0.18884908961676594` Sin[θ[t]] + 
      0.0023324989011712697` θ''[
        t] == -0.000795` ArcTan[
        10.` θ'[t]] + 
      0.0920755` Cos[θ[t]] f[t] - 
      0.00016799999999999996` θ'[t] - 
      0.0004032497194086029` ϕ''[t], 
    0.0004032497194086029` ϕ''[t] == 
     0.0335` u[t] - 
      0.000039255383907286545` ϕ'[t] + 
      0.0004032497194086029` θ''[
        t]}, {θ[0] == 3.0915926535897933`, 
    θ'[0] == 0, ϕ[0] == 0, 
    ϕ'[0] == 0}} /. {u[t] -> 
    42.69342907334017` (-π + θ[t]) + 
     3.88853571287127` θ'[t] + 
     0.21937104569306368` ϕ'[t], 
   f[t] -> 3 E^(-10 (-9 + t)^2) - 3/2 E^(-10 (-6 + t)^2) + 
     7 E^(-10 (-3 + t)^2)}}, {θ[t], ϕ'[t]}, {t, 0, 
     14}] // Evaluate, {t, 0, 14}, PlotRange -> All, 
 ImageSize -> Large, PlotLegends -> {θ, ϕ'}]

error plot

f[t] being where I would normally add my external forces, as my impulse function.

An attempt to add higher working precision to my bumpy function with error:

bumpy[t_] := 7 Exp[-10 (t - 3)^2`20 ] - 3/2 Exp[-10 (t - 6)^2`20 ] + 3 Exp[-10 (t - 9)^2`20]

(*Syntax::sntxf: "(" cannot be followed by "-10 (t-3)^2 `20)".*)

What is the correct way/syntax to write a function with increased precision for further use?

Thanks for the help!

$\endgroup$
3
  • $\begingroup$ Can you post the code that produces errors? $\endgroup$
    – vapor
    Commented Apr 25, 2019 at 22:06
  • $\begingroup$ Hi, yes gladly!, the image of the syntax error is already given with the last bit of code, bumpy[t_] under the attempt which gives the error in the image above it....and I will add an example where NDSolve fails as of version 12. $\endgroup$ Commented Apr 25, 2019 at 22:21
  • $\begingroup$ actually that code does not produce any errors on my machine, that's why I asked... $\endgroup$
    – vapor
    Commented Apr 27, 2019 at 7:57

1 Answer 1

3
$\begingroup$

If working with machine precision produces machine underflow/overflow errors, than you need to work with extended precision numbers. This means that your input cannot contain any machine precision numbers. One possibility is to use Rationalize to convert your ode into exact numbers:

ode = Flatten @ Rationalize[{{{0.18884908961676594` Sin[θ[t]] + 
      0.0023324989011712697` θ''[
        t] == -0.000795` ArcTan[
        10.` θ'[t]] + 
      0.0920755` Cos[θ[t]] f[t] - 
      0.00016799999999999996` θ'[t] - 
      0.0004032497194086029` ϕ''[t], 
    0.0004032497194086029` ϕ''[t] == 
     0.0335` u[t] - 
      0.000039255383907286545` ϕ'[t] + 
      0.0004032497194086029` θ''[
        t]}, {θ[0] == 3.0915926535897933`, 
    θ'[0] == 0, ϕ[0] == 0, 
    ϕ'[0] == 0}} /. {u[t] -> 
    42.69342907334017` (-π + θ[t]) + 
     3.88853571287127` θ'[t] + 
     0.21937104569306368` ϕ'[t], 
   f[t] -> 3 E^(-10 (-9 + t)^2) - 3/2 E^(-10 (-6 + t)^2) + 
     7 E^(-10 (-3 + t)^2)}}, 0];
ode //TeXForm

$\left\{\frac{3559064 \theta ''(t)}{1525858811}+\frac{28353452 \sin (\theta (t))}{150138145}=-\frac{36921618901 \theta '(t)}{219771541077381}-\frac{159 \tan ^{-1}\left(10 \theta '(t)\right)}{200000}+\frac{184151 \left(3 e^{-10 (t-9)^2}-\frac{3}{2} e^{-10 (t-6)^2}+7 e^{-10 (t-3)^2}\right) \cos (\theta (t))}{2000000}-\frac{4587948 \phi ''(t)}{11377436311},\frac{4587948 \phi ''(t)}{11377436311}=\frac{4587948 \theta ''(t)}{11377436311}+\frac{67 \left(\frac{139127231 \theta '(t)}{35778823}+\frac{307971783 (\theta (t)-\pi )}{7213564}+\frac{79283177 \phi '(t)}{361411310}\right)}{2000}-\frac{183308 \phi '(t)}{4669626985},\theta (0)=\frac{118092245}{38197867},\theta '(0)=0,\phi (0)=0,\phi '(0)=0\right\}$

Now, there are no machine numbers polluting your equations. So, use NDSolveValue with a WorkingPrecision option:

sol = NDSolveValue[ode, {θ[t], ϕ'[t]}, {t, 0, 14}, WorkingPrecision->20];

N::meprec: Internal precision limit $MaxExtraPrecision = 50.` reached while evaluating 82222031699886430677801536777088869542973260569651374914500 E^1260 π.

N::meprec: Internal precision limit $MaxExtraPrecision = 50.` reached while evaluating 82222031699886430677801536777088869542973260569651374914500 E^1260 π.

N::meprec: Internal precision limit $MaxExtraPrecision = 50.` reached while evaluating 82222031699886430677801536777088869542973260569651374914500 E^1260 π.

General::stop: Further output of N::meprec will be suppressed during this calculation.

Visualization:

Plot[sol, {t, 0, 14}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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