       Re: Re: A pattern matching problem

• To: mathgroup at smc.vnet.net
• Subject: [mg72551] Re: [mg72544] Re: A pattern matching problem
• From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
• Date: Sat, 6 Jan 2007 23:27:05 -0500 (EST)
• References: <enksb3\$9nt\$1@smc.vnet.net> <200701060838.DAA03832@smc.vnet.net>

```This does not seem to return the answer in the form requested by the
O.P. One similar approach that seems to work is

r = u[t + h] - 2*u[t] + u[t - h] + a2*Derivative[u][t + h/2] +
4*Derivative[u][t - h/4] +
c*(Derivative[u][t + alfa*h]/12);

Prepend[Last /@
Transpose /@
Split[Cases[r, Derivative[i_][u][expr_] :> {i, Coefficient[expr,
h]},
{2}], #1[] == #2[] & ],
Cases[r, u[expr_] :> Coefficient[expr, h], Infinity]

{{0, -1, 1}, {-(1/4), 1/2}, {alfa}}

The extra 0 in {0,-1,1} is due to the presence of the term u[t],
which does not involve h as an argument, and I did no think it work
the trouble to use DeleteCases or something of that kind to get rid
of it.

Andrzej Kozlowski

On 6 Jan 2007, at 08:38, 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
>
>> Here is an interesting challenge in pattern matching.  Suppose
>> you are given an algebraic-differential expression exemplified by
>>
>> 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;
>>
>> Here u[t] is a function of time t, assumed infinitely differentiable,
>> h is a time interval, and primes denote derivatives wrt t.
>> Relation  r==0 is called a delay-differential equation, and is the
>> basic stuff in delayed automatic control (h is the signal "lag").
>>
>> The function name u and the lag h are always symbolic.
>> Function u and its derivatives appear linearly in r, while
>> h always appears linearly in arguments.
>> Coefficients of h may be numeric or symbolic.
>> Coefficients of u & derivatives may be numeric or symbolic.
>>
>> The challenge: given r,  get the coefficients of h as a 2D list,
>> row-ordered by derivative order. Zero coefficients may be omitted.
>> For the above r, it should  return
>>
>>    {{1,-1},{1/2,-1/4},{alfa}}
>>
>> Envisioned module invocation:   clist=LagCoefficients[r,u,t,h,m]
>> with m=max u-derivative order to be considered.  Skeleton:
>>
>>         LagCoefficients[r_,u_,t_,h_,m_]:=Module[ {clist={}},
>>             ??????
>>         Return[clist]];
>>
>> Any ideas for ?????
>>
>

```

• Prev by Date: Re: [TS 35470]--Re:bouncing from error (bug?) to error (bug?)
• Next by Date: Re: Re: Finding paths in graphs
• Previous by thread: Re: A pattern matching problem
• Next by thread: Re: A pattern matching problem