> Consider for example
> f(x) := if x < 0 then `x else `x^2
> How to integrate this function between -2 and 2?
Best advice is:
On Tue, 13 Jul 2004 09:09:46 -0700, Richard Fateman wrote:
> Macsyma's integrate facility integrates explicit algebraic expressions,
> not PROGRAMS.
I just want to restate and summarize what has already been said
(for beginning teachers like myself or students trying to work
problems out of textbooks), 'integrate' or 'plot2d' will not
switch functions as it makes one pass over the x-values.
You would have to write some separate code for this.
If you want to use Maxima to integrate or graph a piece-wise function
from a calculus text book like: f(x) = { x for -2<=x<0, x^2 0<=x<=2 }
there's no need for an IF statement, just do the integrations
or graphs separately and find some way to paste the results together.
Vectors could be used to organize results.
u:[integrate(x,x,-2,0),integrate(x^2,x,0,2)];
8
[- 2, -]
3
u[1]+u[2];
2
-
3
or just
[integrate(x,x,-2,0),integrate(x^2,x,0,2)].[1,1];
MAP would save having to type 'integrate' over and over again.
MAP(INTEGRATE,[x,x^2],[x,x],[-2,0],[0,2]);
For a piecewise plot in Linux (don't know about Windows), using
the gnuplot plot_format, the results from two different plots
can be combined into a data file specified by 'set output'.
(I think this has been mentioned before.)
/*from maxima command line*/
set_plot_option([plot_format,gnuplot]);
plot2d(x,[x,-2,0]);
/*from mgnuplot window*/
set terminal table
set output 'pw-graph'
plot [x=-2:0] x
plot [x=0:2] x*x
set terminal x11
set zeroaxis
set title 'x [-2,0], x^2 [0,2]'
plot 'pw-graph'
L. Prevett
Mathematics Instructor
Cochise College, Sierra Vista, AZ, US
prevettl@cochise.edu