Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #6158 > unrolled thread
| Started by | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| First post | 2011-11-03 08:59 +0000 |
| Last post | 2011-11-10 11:50 +0000 |
| Articles | 6 — 5 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: How to eliminate noises? Bob Hanlon <hanlonr357@gmail.com> - 2011-11-03 08:59 +0000
Re: How to eliminate noises? A better way perhaps. Richard Fateman <fateman@cs.berkeley.edu> - 2011-11-04 11:01 +0000
Re: How to eliminate noises? A better way perhaps. Noqsi <noqsiaerospace@gmail.com> - 2011-11-08 12:18 +0000
Re: How to eliminate noises? A better way perhaps. Andrzej Kozlowski <akoz@mimuw.edu.pl> - 2011-11-09 11:32 +0000
Re: How to eliminate noises? A better way perhaps. DrMajorBob <btreat1@austin.rr.com> - 2011-11-05 09:53 +0000
Re: How to eliminate noises? A better way perhaps. Noqsi <noqsiaerospace@gmail.com> - 2011-11-10 11:50 +0000
| From | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| Date | 2011-11-03 08:59 +0000 |
| Subject | Re: How to eliminate noises? |
| Message-ID | <j8tl5t$f3t$1@smc.vnet.net> |
Use higher precision.
Plot[(-1 + 2 n)^2 (-5077311495040 + 256771815840909 n -
6285087811295946 n^2 + 99108751736880828 n^3 -
1130572436430176064 n^4 + 9932051583279890496 n^5 -
69845429986320295296 n^6 + 403489321408322272512 n^7 -
1949815250878086761472 n^8 + 7985109816575584026624 n^9 -
27976513439837284724736 n^10 + 84423827219928959287296 n^11 -
220448430557212109488128 n^12 + 499528909151513065046016 n^13 -
983522463480512590086144 n^14 + 1682263859668487045185536 n^15 -
2495534893540205641334784 n^16 + 3200240859272788875411456 n^17 -
3529950418080000008257536 n^18 + 3325177849291516859645952 n^19 -
2648782194444972790382592 n^20 + 1760454182292395183308800 n^21 -
958285503480825479430144 n^22 + 416134125894081039040512 n^23 -
138626084433937223909376 n^24 + 33263436995017750609920 n^25 -
5117451845387346247680 n^26 + 379070507065729351680 n^27), {n,
0.35, 0.53}, WorkingPrecision -> 25]
Bob Hanlon
On Wed, Nov 2, 2011 at 7:21 AM, Artur <grafix@csl.pl> wrote:
> Plot[ (-1 + 2 n)^2 (-5077311495040 + 256771815840909 n -
> 6285087811295946 n^2 + 99108751736880828 n^3 -
> 1130572436430176064 n^4 + 9932051583279890496 n^5 -
> 69845429986320295296 n^6 + 403489321408322272512 n^7 -
> 1949815250878086761472 n^8 + 7985109816575584026624 n^9 -
> 27976513439837284724736 n^10 + 84423827219928959287296 n^11 -
> 220448430557212109488128 n^12 + 499528909151513065046016 n^13 -
> 983522463480512590086144 n^14 + 1682263859668487045185536 n^15 -
> 2495534893540205641334784 n^16 + 3200240859272788875411456 n^17 -
> 3529950418080000008257536 n^18 + 3325177849291516859645952 n^19 -
> 2648782194444972790382592 n^20 + 1760454182292395183308800 n^21 -
> 958285503480825479430144 n^22 + 416134125894081039040512 n^23 -
> 138626084433937223909376 n^24 + 33263436995017750609920 n^25 -
> 5117451845387346247680 n^26 + 379070507065729351680 n^27), {n,
> 0.35, 0.53}]
[toc] | [next] | [standalone]
| From | Richard Fateman <fateman@cs.berkeley.edu> |
|---|---|
| Date | 2011-11-04 11:01 +0000 |
| Subject | Re: How to eliminate noises? A better way perhaps. |
| Message-ID | <j90gmp$shi$1@smc.vnet.net> |
| In reply to | #6158 |
On 11/3/2011 1:59 AM, Bob Hanlon wrote:
> Use higher precision.
.. so say you all...
Well, that's the brute force method, and one reason to recommend it is
it doesn't require much thought.
On the other hand, the person asking the question has an apparently
large expression which he knows has a double zero at n=1/2 and he wants
to know the behavior of the expression from 0.35 to 0.53. Namely,
around that zero.
Let us call that expression p. A non-brute force, but mostly automatic
method is to note that (since p is a polynomial of degree 29) it is
EXACTLY equal to s, where
s = Normal[Series[p, {n, 1/2, 29}]]
A plot of s can be done in ordinary float arithmetic and looks to the
eye just like the plot of p, done with high working precision. Unique to
computer algebra systems, it is also possible to look at the structure
of s, and note that expanded around n=1/2 it is mighty sparse.
Let k = n-1/2 . The expression being plotted is then
14 k^2 - 1296 k^5 + 1451188224 k^11 - 2002639749120 k^14 +
598075300380672 k^17 - 83414577743659008 k^20 +
3977900382788517888 k^23 - 113721152119718805504 k^26 +
1516282028262917406720 k^29
Sometimes a better way to format expressions for evaluation is to use
HornerForm. In this case it is
k^2 (14 +
k^3 (-1296 + ....
Evaluating this expression at a value for k requires computing
k^2,k^3,k^6,and some other arithmetic for a total of about 18 arithmetic
operations, which can be done in double-float.
The real win here is that you can show how much more insight you might
get from using computer algebra.
RJF
[toc] | [prev] | [next] | [standalone]
| From | Noqsi <noqsiaerospace@gmail.com> |
|---|---|
| Date | 2011-11-08 12:18 +0000 |
| Subject | Re: How to eliminate noises? A better way perhaps. |
| Message-ID | <j9b6n9$4ta$1@smc.vnet.net> |
| In reply to | #6162 |
On Nov 4, 4:01 am, Richard Fateman <fate...@cs.berkeley.edu> wrote:
> On 11/3/2011 1:59 AM, Bob Hanlon wrote:> Use higher precision.
>
> .. so say you all...
> Well, that's the brute force method, and one reason to recommend it is
> it doesn't require much thought.
>
> On the other hand, the person asking the question has an apparently
> large expression which he knows has a double zero at n=1/2 and he wants
> to know the behavior of the expression from 0.35 to 0.53. Namely,
> around that zero.
>
> Let us call that expression p. A non-brute force, but mostly automatic
> method is to note that (since p is a polynomial of degree 29) it is
> EXACTLY equal to s, where
>
> s = Normal[Series[p, {n, 1/2, 29}]]
>
> A plot of s can be done in ordinary float arithmetic and looks to the
> eye just like the plot of p, done with high working precision. Unique to
> computer algebra systems, it is also possible to look at the structure
> of s, and note that expanded around n=1/2 it is mighty sparse.
>
> Let k = n-1/2 . The expression being plotted is then
>
> 14 k^2 - 1296 k^5 + 1451188224 k^11 - 2002639749120 k^14 +
> 598075300380672 k^17 - 83414577743659008 k^20 +
> 3977900382788517888 k^23 - 113721152119718805504 k^26 +
> 1516282028262917406720 k^29
>
> Sometimes a better way to format expressions for evaluation is to use
> HornerForm. In this case it is
>
> k^2 (14 +
> k^3 (-1296 + ....
>
> Evaluating this expression at a value for k requires computing
> k^2,k^3,k^6,and some other arithmetic for a total of about 18 arithmetic
> operations, which can be done in double-float.
> The real win here is that you can show how much more insight you might
> get from using computer algebra.
I find it a great pleasure to be in agreement with Richard for a
change. But let me offer another perspective, less insightful perhaps,
but more susceptible to automation.
First, let me note the nice behavior of N[Root[]]. For this problem,
it is useful to have all of the roots in numerical form, and I think
the following approach is the best way to get them in Mathematica:
nRoots[p_, x_] :=
With[{f = p /. x -> #}, Table[N[Root[f, n]], {n, 1, Exponent[p, x]}]]
Now, note the the documentation for Root makes the following promise:
"The ordering used by Root[f,k] takes real roots to come before
complex ones, and takes complex conjugate pairs of roots to be
adjacent. " One difficulty with this promise is that it doesn't tell
you how to find the break between the real part of the vector and the
complex part. The following code assumes that N[Root[f,n]] will
reliably have head Real for real roots. Oh Wolfram experts, is this
true?
If you want to blindly make a numerical polynomial for evaluation in
floating point, it is useful to put it in factored form. Factored form
isn't as quick to evaluate as "streamlined" forms like Horner, but it
is more stable. The roots are the raw material you need to create this
form. The real roots correspond to linear terms. The following
function constructs them and collects their product:
linearTerms[r_, x_] := Times @@ (x - # & /@ Cases[r, _Real])
The complex root pairs correspond to quadratic terms. There are
various ways to construct these. This function constructs the form
that Hart et al. ("Computer Approximations", Kreiger 1978, p. 69)
recommend for stability:
quadraticTerm[r_, x_] := With[{z = r[[1]]}, (x - Re[z])^2 + Im[z]^2]
This collects the product of those quadratic terms:
quadraticTerms[r_, x_] :=
Times @@ (quadraticTerm[#, x] & /@ Partition[Cases[r, _Complex], 2])
nFactor[ p, x ] yields a factored numerical representation of
polynomial p in variable x:
nFactor[p_, x_] :=
With[{r = nRoots[p, x]},
N[Coefficient[p, x, Exponent[p, x]]] linearTerms[r,
x] quadraticTerms[r, x]]
Now test it:
nfn = nFactor[(-1 + 2 n)^2 (-5077311495040 + 256771815840909 n -
6285087811295946 n^2 + 99108751736880828 n^3 -
1130572436430176064 n^4 + 9932051583279890496 n^5 -
69845429986320295296 n^6 + 403489321408322272512 n^7 -
1949815250878086761472 n^8 + 7985109816575584026624 n^9 -
27976513439837284724736 n^10 + 84423827219928959287296 n^11 -
220448430557212109488128 n^12 + 499528909151513065046016 n^13 -
983522463480512590086144 n^14 +
1682263859668487045185536 n^15 -
2495534893540205641334784 n^16 +
3200240859272788875411456 n^17 -
3529950418080000008257536 n^18 +
3325177849291516859645952 n^19 -
2648782194444972790382592 n^20 +
1760454182292395183308800 n^21 -
958285503480825479430144 n^22 + 416134125894081039040512 n^23 -
138626084433937223909376 n^24 + 33263436995017750609920 n^25 -
5117451845387346247680 n^26 + 379070507065729351680 n^27), n]
Plot[nfn, {n, 0.35, 0.53}]
This produces the now-familiar plot.
Both this approach and Richard's yield an expression that can be used
for a variety of purposes, including export via CForm[] or
FortranForm[]. Richard's has the advantage that in this case it yields
more human insight, and a more efficient expression. The disadvantage
of Richard's approach is that it *requires* human insight, while this
approach may be applied in a blind, automated fashion.
John Doty Noqsi Aerospace, Ltd.
http://www.noqsi.com/
[toc] | [prev] | [next] | [standalone]
| From | Andrzej Kozlowski <akoz@mimuw.edu.pl> |
|---|---|
| Date | 2011-11-09 11:32 +0000 |
| Subject | Re: How to eliminate noises? A better way perhaps. |
| Message-ID | <j9docr$b30$1@smc.vnet.net> |
| In reply to | #6162 |
On 8 Nov 2011, at 13:15, Noqsi wrote: > Now, note the the documentation for Root makes the following promise: > "The ordering used by Root[f,k] takes real roots to come before > complex ones, and takes complex conjugate pairs of roots to be > adjacent. " One difficulty with this promise is that it doesn't tell > you how to find the break between the real part of the vector and the > complex part. The following code assumes that N[Root[f,n]] will > reliably have head Real for real roots. If f is a polynomial, as it is in your case, than this will be true. The reason is that the roots of a polynomial can always be completely isolated and Mathematica does so the first time a numerical value of a root is used. Although Root isolation uses extended precision arithmetic (it can also be done exactly, if you use the options ExactRootIsolation but that will make the computation slower and should not affect the result), applying N with MachinePrecision to a real Root object should always produce a number with head Real (as long as the coefficients of f are exact; note that Root has the Attribute NHoldAll) By the way, this is not going to be necessarily true when f is a transcendental function. In this case a Root object may represent a cluster of roots, some of which could be real and some not, and it may require high precision arithmetic to decide. In this situation Mathematica will not perform root isolation until sufficient precision is specified. But when f is a polynomial this is not an issue. Andrzej Kozlowski
[toc] | [prev] | [next] | [standalone]
| From | DrMajorBob <btreat1@austin.rr.com> |
|---|---|
| Date | 2011-11-05 09:53 +0000 |
| Subject | Re: How to eliminate noises? A better way perhaps. |
| Message-ID | <j9312o$abq$1@smc.vnet.net> |
| In reply to | #6158 |
Very nice, Richard. We shouldn't be so quick to get the hammer if we think
we've seen a nail!
Bobby
On Fri, 04 Nov 2011 05:59:20 -0500, Richard Fateman
<fateman@cs.berkeley.edu> wrote:
> On 11/3/2011 1:59 AM, Bob Hanlon wrote:
>> Use higher precision.
> .. so say you all...
> Well, that's the brute force method, and one reason to recommend it is
> it doesn't require much thought.
>
> On the other hand, the person asking the question has an apparently
> large expression which he knows has a double zero at n=1/2 and he wants
> to know the behavior of the expression from 0.35 to 0.53. Namely,
> around that zero.
>
> Let us call that expression p. A non-brute force, but mostly automatic
> method is to note that (since p is a polynomial of degree 29) it is
> EXACTLY equal to s, where
>
> s = Normal[Series[p, {n, 1/2, 29}]]
>
> A plot of s can be done in ordinary float arithmetic and looks to the
> eye just like the plot of p, done with high working precision. Unique to
> computer algebra systems, it is also possible to look at the structure
> of s, and note that expanded around n=1/2 it is mighty sparse.
>
> Let k = n-1/2 . The expression being plotted is then
>
> 14 k^2 - 1296 k^5 + 1451188224 k^11 - 2002639749120 k^14 +
> 598075300380672 k^17 - 83414577743659008 k^20 +
> 3977900382788517888 k^23 - 113721152119718805504 k^26 +
> 1516282028262917406720 k^29
>
>
> Sometimes a better way to format expressions for evaluation is to use
> HornerForm. In this case it is
>
>
> k^2 (14 +
> k^3 (-1296 + ....
>
> Evaluating this expression at a value for k requires computing
> k^2,k^3,k^6,and some other arithmetic for a total of about 18 arithmetic
> operations, which can be done in double-float.
> The real win here is that you can show how much more insight you might
> get from using computer algebra.
>
> RJF
>
--
DrMajorBob@yahoo.com
[toc] | [prev] | [next] | [standalone]
| From | Noqsi <noqsiaerospace@gmail.com> |
|---|---|
| Date | 2011-11-10 11:50 +0000 |
| Subject | Re: How to eliminate noises? A better way perhaps. |
| Message-ID | <j9gdp8$oh4$1@smc.vnet.net> |
| In reply to | #6158 |
On Nov 9, 4:32 am, Andrzej Kozlowski <a...@mimuw.edu.pl> wrote: > On 8 Nov 2011, at 13:15, Noqsi wrote: > > > Now, note the the documentation for Root makes the following promise: > > "The ordering used by Root[f,k] takes real roots to come before > > complex ones, and takes complex conjugate pairs of roots to be > > adjacent. " One difficulty with this promise is that it doesn't tell > > you how to find the break between the real part of the vector and the > > complex part. The following code assumes that N[Root[f,n]] will > > reliably have head Real for real roots. > > If f is a polynomial, as it is in your case, than this will be true. The > reason is that the roots of a polynomial can always be completely > isolated and Mathematica does so the first time a numerical value of a > root is used. Although Root isolation uses extended precision arithmetic > (it can also be done exactly, if you use the options ExactRootIsolation > but that will make the computation slower and should not affect the > result), applying N with MachinePrecision to a real Root object should > always produce a number with head Real (as long as the coefficients of > f are exact; note that Root has the Attribute NHoldAll) > > By the way, this is not going to be necessarily true when f is a > transcendental function. In this case a Root object may represent a > cluster of roots, some of which could be real and some not, and it may > require high precision arithmetic to decide. In this situation > Mathematica will not perform root isolation until sufficient precision > is specified. But when f is a polynomial this is not an issue. I should have been more clear. I intended this method to be a way to take an exact polynomial and put it in a stable approximate form. I never thought it would be more general than that. John Doty Noqsi Aerospace, Ltd. http://www.noqsi.com/
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web