Re: Mathematica: adding to some list elements
From: Peter Pein (petsie_at_arcor.de)
Date: 03/17/05
- Next message: Carl K. Woll: "Re: Mathematica: adding to some list elements"
- Previous message: Carl K. Woll: "Re: Mathematica: adding to some list elements"
- In reply to: Carl K. Woll: "Re: Mathematica: adding to some list elements"
- Next in thread: Carl K. Woll: "Re: Mathematica: adding to some list elements"
- Reply: Carl K. Woll: "Re: Mathematica: adding to some list elements"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 17 Mar 2005 17:17:16 +0100
Carl K. Woll wrote:
> "Dave" wrote
>
>>I have a set of data that is phase errors.
>>
>>PhaseErrors={-0.0162231, 0.00826101, -0.0000314291,
>>0.00799775, -0.0162231, -6.29145, -6.28322, -6.29118, -6.29941}
>>
>>
>>Sometimes these are very small (positive or negative), although sometimes
>>they are 2 Pi less than a small number, due to phase wrapping.
>>
>>Whether a phase angle is x, or x-2Pi is irrelevant to me. Hence I want to
>>add 2 Pi to any number in the list that is less than say 0.05, so that all
>>the errors are small, and none show the phase wrapping.
>>
>>Any thoughts on the best way to do this in Mathematica?
>>
>
>
> Dave,
>
> How about
>
> Mod[PhaseErrors,2 Pi, -Pi]
>
> Carl Woll
>
>
>
>
>
Nice and easy for small lists, but:
pe = Table[Random[]/10 - If[Random[] < 0.01, 2*Pi, 0], {10^6}];
Timing[p1=Mod[pe, 2*Pi, -Pi]; ]
{26.562 Second, Null}
Timing[p2=pe /. x_ /; x < -0.05 -> 2*Pi + x; ]
{1.438 Second, Null}
p1 === p2
True
-- Peter Pein Berlin
- Next message: Carl K. Woll: "Re: Mathematica: adding to some list elements"
- Previous message: Carl K. Woll: "Re: Mathematica: adding to some list elements"
- In reply to: Carl K. Woll: "Re: Mathematica: adding to some list elements"
- Next in thread: Carl K. Woll: "Re: Mathematica: adding to some list elements"
- Reply: Carl K. Woll: "Re: Mathematica: adding to some list elements"
- Messages sorted by: [ date ] [ thread ]