Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Help with Loop to Rule Based Algorithm

  • To: mathgroup at smc.vnet.net
  • Subject: [mg114803] Re: Help with Loop to Rule Based Algorithm
  • From: Daniel Lockhart <daniel.lockhart at gmail.com>
  • Date: Fri, 17 Dec 2010 03:31:12 -0500 (EST)
  • References: <201012161048.FAA11817@smc.vnet.net>

Sseziwa,

Thanks for the reply!

u[i] is not constant, so I suppose I need to use Fold or ListFold to to this.

Any ideas on how to make Fold or ListFold a function of the current
frame in the Table?

Daniel


On Thu, Dec 16, 2010 at 6:57 AM, Sseziwa Mukasa <mukasa at jeol.com> wrote:
>
> On Dec 16, 2010, at 5:48 AM, Daniel Lockhart wrote:
>
>> Hi all,
>>
>> I have been a long time Mathematica user, but have always had problems writing Mathematica code using rules from existing algorithms that utilize loops.
>>
>> Suppose I want to write a simple smoothing filter, but not use any built-in Mathematica algorithm. Just to make the point, I want the smoothing gain/coefficient to be a nonlinear function. So, I want this pseudocode:
>>
>> x_{1} = u{1};
>> for i = 2 to N
>>  alpha = f(x, u);
>>  x_{i} = x_{i-1} + alpha * (u_{i} - x_{i-1});
>> end for;
>>
>> if u is the input data, and f(x, u) is a nonlinear function of x and u. If alpha was constant and 0 < alpha < 1, x would be some sort of moving average of u.
>>
>> How can I do this in Mathematica without writing an explicit loop? I am guessing some from of recursive Map, but I am at a loss on how to start.
>>
>> Thanks!
>
> You didn't specify u_{i}, I assume u_{i} = u_{1}, otherwise just use Nest
>
> Nest[#+f[#,u] (u-#)&,u,n]
>
> Note, don't use capital N as a variable name, in general don't use variable names with initial capital letters to avoid name collision with predefined functions.
>
> Regards,
>        Sseziwa
>
> PS - If u_{i} /= u_{1} use Fold,
>
> Fold[#+f[#,#2] (#2-#)&,First[u],Rest[u]]
>
> Assuming u is a list of the u_{i}.
>
>


  • Prev by Date: Re: Defining a distribution
  • Next by Date: Re: VectorPlot on a Circle
  • Previous by thread: Re: Help with Loop to Rule Based Algorithm
  • Next by thread: Re: Help with Loop to Rule Based Algorithm