On 2/15/08, Alexander Ray <riccio at gmx.at> wrote:
> Is it possible/easy to define in MAXIMA a generic SYMBOLIC function of
> the following form?
>
> F( x, (x11,x12,f1(x)), (x21,x22,f2(x), ... )
>
> ==
>
> f1(x), if x in [x11,x12]
> f2(x), if x in [x21,x22]
> ...
> 0, if x elsewhere
The good news is that it is possible, the bad news is that it is not simple,
and the moderately good news is that given the existing machinery in
Maxima, we could probably figure out a way to equip Maxima with
that capability. Given that functions defined piecewise are a recurring
source of questions, I'm inclined to think we should go ahead & do it.
Here is an initial attempt to solve your problem in terms of the
unit_step function.
A solution could probably also be formulated in terms of conditional
expressions. I hope I haven't made some kind of fundamental error here.
load (orthopoly);
matchdeclare (aa, all, xx, mapatom);
tellsimpafter ('diff (unit_step(aa), xx, 1), if freeof (xx,aa) then 0
else delta (aa));
More stuff has to be thrown in to handle the delta(x) stuff.
I'll let it go for now. Here's what we can get with just that rule.
foo : f(x) * (1 - unit_step (x - 3)) + g(x) * unit_step (x - 3);
diff (foo, x);
=> unit_step(x - 3) * 'diff(g(x),x,1) + (1 - unit_step(x - 3)) *
'diff(f(x),x,1) + delta(x - 3) * g(x) - delta(x - 3) * f(x)
In case it isn't clear, "f1(x), if x in [x11, x12]" is represented as
f1(x) * (unit_step (x - x11) - unit_step (x - x12)).
Hope this helps. Sorry that Maxima cannot do a better job on this stuff.
Robert Dodier