Re: Programming question: Iterative solution

• To: mathgroup at smc.vnet.net
• Subject: [mg22887] Re: [mg22877] Programming question: Iterative solution
• From: Andrzej Kozlowski <andrzej at bekkoame.ne.jp>
• Date: Tue, 4 Apr 2000 01:25:24 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```on 4/3/00 1:04 PM, J.Guillermo Sanchez at guillerm at gugu.usal.es wrote:

>
> Dear Friend, I have an iterative problem
>
> Given the list:
>
> In[1]:=
> list1 = {1.90, 3.625, 5.18, 6.59, 7.87, 9.02, 10.07, 11.01, 11.87, 12.64};
>
> and the equation (besed on trapezoid approximation for an integral)
>
> In[2]:=
> f[n_Integer] :=
> Simplify[Sum[g[j - 1]*i[n - j + 1] + g[j]*i[n - j], {j, 1, n}] /. g[0] -> 0]
>
> where
>
> In[3]:=
> g[n_Integer] := E^(-0.1*n) /; n > 0
>
> I would like find the solution for any i[n]. I have precedured as follow
>
> In[4]:=
> sol[n_Integer] := Solve[f[n + 1] == Extract[list1, n + 1] , i[n]]
>
> Now,  I can find the solution . E.g.
>
> In[5]:=
> sol[0]
>
> Out[5]=
> {{i[0] -> 2.09982}}
>
> In[6]:=
> sol[1] /. sol[0]
>
> Out[6]=
> {{{i[1] -> 1.05312}}}
>
> In[7]:=
> sol[2] /. sol[1] /. sol[0]
>
> Out[7]=
> {{{{i[2] -> 1.04989}}}}
>
> But I thing is not to good method,
>
> Can any body give me a more elegant solution?. Thanks
>
>
>

In[2]:= sol[n_] := Flatten[Apply[Solve, Transpose[Map[{f[# + 1] == list1[[#
+ 1]], i[#]} &, Range[0, n]]]]]

Then
In[2]:= sol[4]
Out[2]=
{i[0] -> 2.09982, i[1] -> 1.05312, i[2] -> 1.04989, i[3] -> 1.05154,
i[4] -> 1.05385}

Now, for example, if you only need i[3] you can do

In[3]:=
i[3] /. %
Out[3]=
1.05154

Andrzej Kozlowski

Toyama International University
Toyama, Japan

```

• Prev by Date: Re: Exporting formulae as GIFs
• Next by Date: Re: Trying to define: Fractional Derivatives & Leibniz' display form for output and templates
• Previous by thread: Programming question: Iterative solution
• Next by thread: Re: Trying to define: Fractional Derivatives & Leibniz' display form for output and templates