Re: A pattern matching problem

• To: mathgroup at smc.vnet.net
• Subject: [mg72557] Re: A pattern matching problem
• Date: Mon, 8 Jan 2007 04:56:33 -0500 (EST)
• References: <enksb3\$9nt\$1@smc.vnet.net><ennmu1\$3mc\$1@smc.vnet.net>

Jens-Peer Kuska wrote:
> Hi,
>
> what is with
>
> r = u[t + h] - 2*u[t] + u[t - h] + a2*u'[t + h/2] + 4*u'[t - h/4] + c*
>        u''[t + alfa*h]/12;
>
> (Cases[r, u[_] |
>          Derivative[__][u][_], Infinity] /. {u[
>                  arg_] :> {0, arg}, Derivative[i_][u][arg_] :> {i,
>         arg}}) /. {order_Integer, arg_} :> {order, D[arg, h]}
>
> Regards
>    Jens

Many thanks, that is a very good start.  I completed the module as
follows:

LagCoefficients[r_,u_,h_]:=Module[{clag,d,nd,md,ider,htab},
clag=(Cases[r,u[_]|Derivative[__][u][_],Infinity]/.{u[arg_]:>{0,arg},
Derivative[i_][u][arg_]:>{i,arg}})/.
{order_Integer,arg_}:>{order,D[arg,h]};
If [Length[clag]==0, Return[{}]];
d=Table[clag[[i,1]],{i,1,Length[clag]}]; md=Max[d];
nd=Table[Count[d,i],{i,0,md}]; htab=Table[{},{i,1,md+1}];
For [i=1,i<=Length[clag],i++, {ider,c}=clag[[i]];
If [c==0,Continue[]]; AppendTo[htab[[ider+1]],c] ];
Return[htab]];

Test:

r = u[t+h]-2*u[t]+u[t-h]+a^2*u'[t+h/2]+4*u'[t-h/4]+c*u''[t+alfa*h]/12;
htab=LagCoefficients[r,u,h];

returns  {{-1, 1}, {-1/4, 1/2}, {alfa}}   in htab, which is correct.

However boundary cases give me trouble.  For example  r=u[t+h]