Re: Newbie Question
- To: mathgroup at smc.vnet.net
- Subject: [mg32749] Re: [mg32686] Newbie Question
- From: BobHanlon at aol.com
- Date: Fri, 8 Feb 2002 03:49:21 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
In a message dated 2/6/02 6:39:26 AM, kbrunsman at ou.edu writes: >I can't believe that I am asking this question, but ... I'm tired of Fortran >and find the symbolic part of Mathematica extremely useful. > >I have a list with Dimensions = {10,000, 6} and I need to find the Percent >Difference between items in a column. > >I can parse out the column I need using Take [data [[All, Column #]]] --- >no >big deal. So far, so good. > >Now here's the problem --- How do I get % Differences between any of 10,000 >items in that list? I need to take % Differences between adjacent pairs, >i.e. n and n-1, as well as items n and n-m where m can range from 1 to >10,000. > relativeChange[data_List, m_Integer] := (RotateLeft[data,m]-data)/data; data=Table[ToExpression["x"<>ToString[k]],{k,1,4}]; Percent difference of adjacent elements 100*relativeChange[data,1] {(100*(x2 - x1))/x1, (100*(x3 - x2))/x2, (100*(x4 - x3))/x3, (100*(x1 - x4))/x4} 100*relativeChange[data,-1] {(100*(x4 - x1))/x1, (100*(x1 - x2))/x2, (100*(x2 - x3))/x3, (100*(x3 - x4))/x4} Percent difference of elements offset by m 100*relativeChange[data,3] {(100*(x4 - x1))/x1, (100*(x1 - x2))/x2, (100*(x2 - x3))/x3, (100*(x3 - x4))/x4} 100*relativeChange[data,-3] {(100*(x2 - x1))/x1, (100*(x3 - x2))/x2, (100*(x4 - x3))/x3, (100*(x1 - x4))/x4} Bob Hanlon Chantilly, VA USA