Topic: Defining a Piece-wise Function to Integrate

I currently plot a piece-wise function as a set of functions on each necessary subinterval to obtain the graph of the piecewise function. I would love to be able to have Graph calculate the definite integral of the piece-wise defined function, which is all of the functions put together. Right now, if I use the definite integral function, it will only give me the result for each piece; not the graph treated as a whole.
I'm trying to define a custom function which is a single function so that Graph can calculate the definite integral, but I am not having luck.
For instance, to be able to graph f(x) = x for x<1 and g(x) = -(x-1)^2+1 for x>=1. Be able to define h(x) = f(x) + g(x), and have Graph integrate h(x) from x=0 to x=2.
I've attached a graph file of a piece-wise function and shading to represent the integral I'd like Graph to be able to calculate. If you know how to have Graph calculate that integral in one shot let me know.


Re: Defining a Piece-wise Function to Integrate

You could define the custom function:

gate(x,a,b) = u(x-a)*u(b-x)

Then, you will create a single expression for all pieces:

s(x) = f(x)*gate(x,a1,b1) + g(x)*gate(x,a2,b2) + .......

This expression can be integrated from a1 to the last b.

Re: Defining a Piece-wise Function to Integrate

You can use if to combine your two functions like this:
f(x)=if(x<1, x, -(x-1)^2+1)

You can combine as many functions as you like. Here is an example with four functions:
if(x<0, -6, x<3, x^2-6, x<5, 3, x-2)

However I will warn agains calculating integrals over combined functions. The algorithm used to calculate definite integrals do not expect piecewise functions and will not give as accurate a result as if you do the calculation on each part separately.