Hi all,
I was going through the archives and I have the same problem - How to
represent a piecewise continuous function and how to integrate it. I
found the following post by Larry which beautifully explains the
integration provided the whole piece belongs to one section. But what
should I do to make it work across pieces. Consider for example
f(x) := if x < 0 then `x else `x^2
How to integate this function between -2 and 2?
thanks
raju
Prevett, Larry wrote:
>|After reading through the docs, I'm still puzzled by the following:
>|if I define f(x) as follows
>|f(x) := IF x < 0 THEN 0 ELSE 1;
>|then
>|integrate(f(x), x ,1,2);
>|gives the error
>
>|MACSYMA was unable to evaluate the predicate:
>|x < 0
>|#0: f(x=x)
>| -- an error. Quitting. To debug this try DEBUGMODE(TRUE);)
>|Is there a "proper" way to integrate piecewise functions in Maxima?
>|Pieter
>
>
>Here's another IF definition with variable expressions.
>
>f(x):=IF x < 0 THEN x ELSE x^2$
>
>f(-2);
>
> - 2
>f(2);
>
> 4
>
>If you suppress the evaluation of f(x) with the single quote,
>you get a symbolic expression,
>
> integrate('f(x),x,1,2);
>
> 2
> /
> [
>(D3) I f(x) dx
> ]
> /
> 1
>
>but you need to find some way to allow
>Maxima to evaluate what f(x) is before
>it can do the integral. And you do not
>want f(x) to be evaluated as a number in the
>case of a variable expression.
>
>So use single quotes in the IF definition
>to prevent Maxima from evaluating the expression.
>
>f(x):=IF x < 0 THEN 'x ELSE 'x^2$
>
>f(-2);
>
> x
>f(2);
>
> 2
> x
>
>One way to help Maxima decide which function to use
>is with ASSUME (may be other ways with EV ... ?? )
>
>(C2) assume(a>0);
>
>(D2) [a > 0]
>(C3) INTEGRATE(f(a),x,1,3);
>
> 26
>(D3) --
> 3
>starting again ...
>
>(C4) kill(ALL)$
>
>(C1) f(x):=IF x < 0 THEN 'x ELSE 'x^2$
>
>(C2) assume(a<0)$
>
>(C3) INTEGRATE(f(a),x,-3,-1);
>
>(D3) - 4
>
>This answer doesn't solve all your problems, but maybe it'll
>help. Also, I don't quite understand why the kill(all) command
>is necessary before the second ASSUME, I get a
>"[INCONSISTENT]" message if I don't use it (RH9,maxima-5.9.0rc3-1).
>Maybe someone else has a better solution.
>
>I think I remember reading on the list that Maxima support
>for piecewise functions is still not fully complete.
>
>See:
> describe(assume);
> describe(ev);
> example(ev);
>
>lp
>
>
>_______________________________________________
>Maxima mailing list
>Maxima@www.math.utexas.edu
>http://www.math.utexas.edu/mailman/listinfo/maxima
>
>
>