Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #10635 > unrolled thread
| Started by | Cyril <cyril.stephanos@gmail.com> |
|---|---|
| First post | 2012-06-26 08:50 +0000 |
| Last post | 2012-07-05 10:14 +0000 |
| Articles | 7 — 4 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Higher precision in Error function Erf[] needed. Cyril <cyril.stephanos@gmail.com> - 2012-06-26 08:50 +0000
Re: Higher precision in Error function Erf[] needed. Ray Koopman <koopman@sfu.ca> - 2012-06-27 08:06 +0000
Re: Higher precision in Error function Erf[] needed. Cyril <cyril.stephanos@gmail.com> - 2012-06-29 08:55 +0000
Re: Higher precision in Error function Erf[] needed. Ray Koopman <koopman@sfu.ca> - 2012-06-30 09:17 +0000
Re: Higher precision in Error function Erf[] needed. "Nasser M. Abbasi" <nma@12000.org> - 2012-07-02 09:28 +0000
Re: Higher precision in Error function Erf[] needed. Ray Koopman <koopman@sfu.ca> - 2012-07-04 07:30 +0000
Re: Higher precision in Error function Erf[] needed. "Alexey Popkov" <lehin.p@gmail.com> - 2012-07-05 10:14 +0000
| From | Cyril <cyril.stephanos@gmail.com> |
|---|---|
| Date | 2012-06-26 08:50 +0000 |
| Subject | Higher precision in Error function Erf[] needed. |
| Message-ID | <jsbt4i$6pq$1@smc.vnet.net> |
Hi everyone
I am using the error function as part of differential equations I am solving with NDSolve.
Unfortunately, for certain parameters, the error function Erf[] starts oscillating and yielding wrong values.
The oscillation does not show when I plot the error function itself, but when I plot this expression
Plot[Exp[8*(10 - Abs[10 - 20000*x])]*(1 - Erf[(8*(10 - Abs[10 - 20000*x]))^(1/2)]), {x, 0, 1*10^(-3)}, PlotRange -> Full]
it becomes visible.
When I do the integration for error function with NDSolve manually and plot the expression, the oscillation vanishes for high values of PrecisionGoal and WorkingPrecision, e.g.
Plot[ Exp[8*(10 - Abs[10 - 20000*x])]*(1 - NIntegrate[ 2/Sqrt[Pi] Exp[-t^2], {t, 0, (8*(10 - Abs[10 - 20000*x]))^(1/2)}, PrecisionGoal -> 40, WorkingPrecision -> 40]), {x, 0, 1*10^(-3)}, PlotRange -> Full]
The oscillation of Erf[] is not only visible in the plot, it also leads to wrong results in my calculations.
I tried to increase the precision of Erf[] by using N[Erf[],n] with very high values for n - as described in the Mathematica help - but it does not change anything.
Solving the Integral for the error function manually with NDSolve yields two problems. It is very slow - it takes about three minutes on my computer (I have to solve many equations) - whereas Erf[] is much faster. And it seems that I cannot use NDSolve as part of an equation I want to solve with NDSolve itself.
Is there a possibility to increase the precision of Erf[] and obtain more accurate results?
Thank you in advance for your help.
Best regards
Cyril
[toc] | [next] | [standalone]
| From | Ray Koopman <koopman@sfu.ca> |
|---|---|
| Date | 2012-06-27 08:06 +0000 |
| Message-ID | <jseeua$i3d$1@smc.vnet.net> |
| In reply to | #10635 |
On Jun 26, 1:50 am, Cyril <cyril.stepha...@gmail.com> wrote:
> Hi everyone
>
> I am using the error function as part of differential equations I am solving with NDSolve.
> Unfortunately, for certain parameters, the error function Erf[] starts oscillating and yielding wrong values.
>
> The oscillation does not show when I plot the error function itself, but when I plot this expression
>
> Plot[Exp[8*(10 - Abs[10 - 20000*x])]*(1 - Erf[(8*(10 - Abs[10 - 20000*x]))^(1/2)]), {x, 0, 1*10^(-3)}, PlotRange -> Full]
>
> it becomes visible.
>
> When I do the integration for error function with NDSolve manually and plot the expression, the oscillation vanishes for high values of PrecisionGoal and WorkingPrecision, e.g.
>
> Plot[ Exp[8*(10 - Abs[10 - 20000*x])]*(1 - NIntegrate[ 2/Sqrt[Pi] Exp[-t^2], {t, 0, (8*(10 - Abs[10 - 20000*x]))^(1/2)}, PrecisionGoal -> 40, WorkingPrecision -> 40]), {x, 0, 1*10^(-3)}, PlotRange -> Full]
>
> The oscillation of Erf[] is not only visible in the plot, it also leads to wrong results in my calculations.
>
> I tried to increase the precision of Erf[] by using N[Erf[],n] with very high values for n - as described in the Mathematica help - but it does not change anything.
>
> Solving the Integral for the error function manually with NDSolve yields two problems. It is very slow - it takes about three minutes on my computer (I have to solve many equations) - whereas Erf[] is much faster. And it seems that I cannot use NDSolve as part of an equation I want to solve with NDSolve itself.
>
> Is there a possibility to increase the precision of Erf[] and obtain more accurate results?
>
> Thank you in advance for your help.
>
> Best regards
> Cyril
Change (1 - Erf[...]) to Erfc[...] .
[toc] | [prev] | [next] | [standalone]
| From | Cyril <cyril.stephanos@gmail.com> |
|---|---|
| Date | 2012-06-29 08:55 +0000 |
| Message-ID | <jsjqhg$d2j$1@smc.vnet.net> |
| In reply to | #10659 |
On Wednesday, June 27, 2012 10:06:34 AM UTC+2, Ray Koopman wrote:
> On Jun 26, 1:50 am, Cyril <cyril.stepha...@gmail.com> wrote:
> > Hi everyone
> >
> > I am using the error function as part of differential equations I am solving with NDSolve.
> > Unfortunately, for certain parameters, the error function Erf[] starts oscillating and yielding wrong values.
> >
> > The oscillation does not show when I plot the error function itself, but when I plot this expression
> >
> > Plot[Exp[8*(10 - Abs[10 - 20000*x])]*(1 - Erf[(8*(10 - Abs[10 - 20000*x]))^(1/2)]), {x, 0, 1*10^(-3)}, PlotRange -> Full]
> >
> > it becomes visible.
> >
> > When I do the integration for error function with NDSolve manually and plot the expression, the oscillation vanishes for high values of PrecisionGoal and WorkingPrecision, e.g.
> >
> > Plot[ Exp[8*(10 - Abs[10 - 20000*x])]*(1 - NIntegrate[ 2/Sqrt[Pi] Exp[-t^2], {t, 0, (8*(10 - Abs[10 - 20000*x]))^(1/2)}, PrecisionGoal -> 40, WorkingPrecision -> 40]), {x, 0, 1*10^(-3)}, PlotRange -> Full]
> >
> > The oscillation of Erf[] is not only visible in the plot, it also leads to wrong results in my calculations.
> >
> > I tried to increase the precision of Erf[] by using N[Erf[],n] with very high values for n - as described in the Mathematica help - but it does not change anything.
> >
> > Solving the Integral for the error function manually with NDSolve yields two problems. It is very slow - it takes about three minutes on my computer (I have to solve many equations) - whereas Erf[] is much faster. And it seems that I cannot use NDSolve as part of an equation I want to solve with NDSolve itself.
> >
> > Is there a possibility to increase the precision of Erf[] and obtain more accurate results?
> >
> > Thank you in advance for your help.
> >
> > Best regards
> > Cyril
>
> Change (1 - Erf[...]) to Erfc[...] .
Ok, that was easy and works perfect. Thanks a lot!
Although it was not what I expected. Is there a possibility to alter the precision of Erf[]?
Best regards
Cyril
[toc] | [prev] | [next] | [standalone]
| From | Ray Koopman <koopman@sfu.ca> |
|---|---|
| Date | 2012-06-30 09:17 +0000 |
| Message-ID | <jsmg81$1jj$1@smc.vnet.net> |
| In reply to | #10691 |
On Jun 29, 1:55 am, Cyril <cyril.stepha...@gmail.com> wrote:
> On Wednesday, June 27, 2012 10:06:34 AM UTC+2, Ray Koopman wrote:
>> On Jun 26, 1:50 am, Cyril <cyril.stepha...@gmail.com> wrote:
>>> Hi everyone
>>>
>>> I am using the error function as part of differential equations I
>>> am solving with NDSolve. Unfortunately, for certain parameters, the
>>> error function Erf[] starts oscillating and yielding wrong values.
>>>
>>> The oscillation does not show when I plot the error function itself,
>>> but when I plot this expression
>>>
>>> Plot[Exp[8*(10 - Abs[10 - 20000*x])]*(1 - Erf[(8*(10 - Abs[10 -
>>> 20000*x]))^(1/2)]), {x, 0, 1*10^(-3)}, PlotRange -> Full]
>>>
>>> it becomes visible.
>>>
>>> When I do the integration for error function with NDSolve manually
>>> and plot the expression, the oscillation vanishes for high values
>>> of PrecisionGoal and WorkingPrecision, e.g.
>>>
>>> Plot[ Exp[8*(10 - Abs[10 - 20000*x])]*(1 - NIntegrate[ 2/Sqrt[Pi]
>>> Exp[-t^2], {t, 0, (8*(10 - Abs[10 - 20000*x]))^(1/2)},
>>> PrecisionGoal -> 40, WorkingPrecision -> 40]), {x, 0, 1*10^(-3)},
>>> PlotRange -> Full]
>>>
>>> The oscillation of Erf[] is not only visible in the plot,
>>> it also leads to wrong results in my calculations.
>>>
>>> I tried to increase the precision of Erf[] by using N[Erf[],n]
>>> with very high values for n - as described in the Mathematica help
>>> - but it does not change anything.
>>>
>>> Solving the Integral for the error function manually with NDSolve
>>> yields two problems. It is very slow - it takes about three minutes
>>> on my computer (I have to solve many equations) - whereas Erf[] is
>>> much faster. And it seems that I cannot use NDSolve as part of an
>>> equation I want to solve with NDSolve itself.
>>>
>>> Is there a possibility to increase the precision of Erf[]
>>> and obtain more accurate results?
>>>
>>> Thank you in advance for your help.
>>>
>>> Best regards
>>> Cyril
>>
>> Change (1 - Erf[...]) to Erfc[...] .
>
> Ok, that was easy and works perfect. Thanks a lot!
>
> Although it was not what I expected.
> Is there a possibility to alter the precision of Erf[]?
>
> Best regards
> Cyril
Just alter the precision of its input. First define
f[x_,n_] := 8*(10 - Abs[10 - 20000*SetPrecision[x,n]])
Then
Plot[Exp@#*(1-Erf@Sqrt@#)&@f[x,20], {x,0,10^-3}, Compiled->False]
works fine.
[toc] | [prev] | [next] | [standalone]
| From | "Nasser M. Abbasi" <nma@12000.org> |
|---|---|
| Date | 2012-07-02 09:28 +0000 |
| Message-ID | <jsrpkh$d3i$1@smc.vnet.net> |
| In reply to | #10696 |
On 6/30/2012 4:17 AM, Ray Koopman wrote:
>
> Just alter the precision of its input. First define
>
> f[x_,n_] := 8*(10 - Abs[10 - 20000*SetPrecision[x,n]])
>
> Then
>
> Plot[Exp@#*(1-Erf@Sqrt@#)&@f[x,20], {x,0,10^-3}, Compiled->False]
>
> works fine.
>
fyi;
using Mathematica 8, the 'Compiled->False' is shown in RED
letters, meaning is not valid option for Plot.
on a side note, I myself, and this is just a styling thing,
when using pure function, find it easier to use @ for
only the RHS of the pure function. Hence the above command
would become
Plot[ Exp[#] * (1-Erf[Sqrt[#]])& @f[x,20], {x,0,10^-3}]
vs.
Plot[Exp@# * (1-Erf@Sqrt@#)& @f[x,20], {x,0,10^-3}]
Again, just different styling, all is valid, but for me, I
find the first case above a little easier to read, since @ is
used only for the pure function argument.
regards,
--Nasser
[toc] | [prev] | [next] | [standalone]
| From | Ray Koopman <koopman@sfu.ca> |
|---|---|
| Date | 2012-07-04 07:30 +0000 |
| Message-ID | <jt0rdo$1ah$1@smc.vnet.net> |
| In reply to | #10659 |
On Jul 2, 2:28 am, "Nasser M. Abbasi" <n...@12000.org> wrote:
> On 6/30/2012 4:17 AM, Ray Koopman wrote:
>
>> Just alter the precision of its input. First define
>>
>> f[x_,n_] := 8*(10 - Abs[10 - 20000*SetPrecision[x,n]])
>>
>> Then
>>
>> Plot[Exp@#*(1-Erf@Sqrt@#)&@f[x,20], {x,0,10^-3}, Compiled->False]
>>
>> works fine.
>
> fyi;
>
> using Mathematica 8, the 'Compiled->False' is shown in RED
> letters, meaning is not valid option for Plot.
So the advice at
<http://reference.wolfram.com/mathematica/ref/Compiled.html>
to use Compiled->False when plotting is "no longer operative"?
[toc] | [prev] | [next] | [standalone]
| From | "Alexey Popkov" <lehin.p@gmail.com> |
|---|---|
| Date | 2012-07-05 10:14 +0000 |
| Message-ID | <jt3pes$12r$1@smc.vnet.net> |
| In reply to | #10773 |
I just tried both variants:
Plot[If[Exp[-x] == 0., 0, -1] + x/900, {x, 0, 1000}, Compiled -> False]
Plot[If[Exp[-x] == 0., 0, -1] + x/900, {x, 0, 1000},
Method -> {Compiled -> False}]
In the first case Compiled is shown in red but it works as it should
according to the documentation page you referenced. But the second method
suggested on that documentation page does not work.
P.S. Using Trace, I discovered potentially useful error message of Plot:
On[Plot::accbend]
Plot[If[Exp[-x] == 0., 0, -1] + x/900, {x, 0, 1000}]
(*=> Plot::accbend: Target bending angle of 4.999999999999992` not
satisfied; current maximal bending angle is 72.68343019044056`. >>*)
"Ray Koopman" <koopman@sfu.ca> wrote: news:jt0rdo$1ah$1@smc.vnet.net...
> On Jul 2, 2:28 am, "Nasser M. Abbasi" <n...@12000.org> wrote:
>> On 6/30/2012 4:17 AM, Ray Koopman wrote:
>>
>>> Just alter the precision of its input. First define
>>>
>>> f[x_,n_] := 8*(10 - Abs[10 - 20000*SetPrecision[x,n]])
>>>
>>> Then
>>>
>>> Plot[Exp@#*(1-Erf@Sqrt@#)&@f[x,20], {x,0,10^-3}, Compiled->False]
>>>
>>> works fine.
>>
>> fyi;
>>
>> using Mathematica 8, the 'Compiled->False' is shown in RED
>> letters, meaning is not valid option for Plot.
>
> So the advice at
> <http://reference.wolfram.com/mathematica/ref/Compiled.html>
> to use Compiled->False when plotting is "no longer operative"?
>
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web