[Date Index]
[Thread Index]
[Author Index]
Re: Smooth the data in a table, Why this cannot work?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg62539] Re: Smooth the data in a table, Why this cannot work?
*From*: Bill Rowe <readnewsciv at earthlink.net>
*Date*: Sun, 27 Nov 2005 02:40:42 -0500 (EST)
*Sender*: owner-wri-mathgroup at wolfram.com
On 11/26/05 at 2:47 AM, yanshanguke at 163.com (simon yang) wrote:
>Hello, every one. I meet a problem when I smooth the data in a
>table:
>280.00,.000
>282.00,.002
>284.00,.002
>286.00,.000
>288.00,.000
>290.00,.002
>292.00,.003
>294.00,.003
>296.00,.003
>298.00,.011
>300.00,.031
>302.00,.076
>The method I used is:
>For[i=3,i<=9,data[[1,i]][[2]] = (1/35)( -3(data[[1,i-3]][[2]]
>+data[[1,i+3]][[2]]) +12(data[[1,i-2]][[2]] +data[[1,i+2]][[2]])
>+17(data[[1,i-1][[2]] +data[[1,i+1]][[2]])); i++]
>it doen't work
Correct, it won't work. There are two problems above both related to incorrect index syntax. First, in Mathematica the starting index value is 1 not 0. For, i=3, data[[i, i-3]] evaluates to data[[3,0]] which is invalid.
Second, you have an array consisting of two columns and several rows. The syntax data[[i,j]] refers to one element of that array which is a number. The syntac data[[i,j]][[2]] attempts to find part 2 of data element i,j which doesn't exist.
>the function Replace[] also don't work \!\(For[i = 3,
>i = \ 9, Replace[ datatemp, \(data[\([1, i]\)]\)[\([2]\)] ->
>\(1\/35\) \((\(-3\) \
>\((\(data[\([1, i - 2]\)]\)[\([2]\)] + \(data[\([1, i +
>2]\)]\)[\([2]\)])\) +
>12 \((\(data[\([1, i - 1]\)]\)[\([2]\)] + \(data[\([1, i +
>1]\)]\)[\([2]\)])\)
>+
>17 \( data[\([1, i]\)]\)[\([2]\)])\)];
>\(i++\)]\)
Here you have corrected the issue of gettting data[[3,0]] but still have the issue of trying to find a non-existant part.
>Then what should I do ?
Correcting the syntax should fix your problem. But better would be to avoid using the For loop all together.
You appear to be using linear smoothing with coefficients (-3, 12, 17, 12, -3)/35. Either ListConvolve or ListCorrelate will do what you want much more efficiently. That is
In[1]:=
data = {{280., 0.}, {282., 0.002}, {284., 0.002},
{286., 0.}, {288., 0.}, {290., 0.002},
{292., 0.003}, {294., 0.003}, {296., 0.003},
{298., 0.011}, {300., 0.031}, {302., 0.076}};
In[2]:=
ListConvolve[{-3, 12, 17, 12, -3}/35, Last/@data]
Out[2]=
{0.001657142857142857,
0.0003428571428571429,
0.00025714285714285715,
0.0017428571428571428,
0.002914285714285714,
0.0024000000000000002,
0.0033428571428571426,
0.01022857142857143}
appears to be the result you want.
In addition, you might want to look at the package Statistics`DataSmoothing`
--
To reply via email subtract one hundred and four
Prev by Date:
**Re: Re: SugarCube**
Next by Date:
**Re: Smooth the data in a table, Why this cannot work?**
Previous by thread:
**Smooth the data in a table, Why this cannot work?**
Next by thread:
**Re: Smooth the data in a table, Why this cannot work?**
| |