Ask Your Question

Integrate piecewise function with change of variable

asked 2017-03-28 18:28:56 -0500

jrojasqu gravatar image

I would like to integrate a piecewise defined function while operating a change of variable. I start by defining the function and another variable involved in the change of variable:

phi(x)   = piecewise([([-1,1], (1-abs(x))*(1-abs(x))*(1+2*abs(x)))]);
phi(x)   = phi.extension(0); 

What I would like to do is integrate the function phi(x/h-1) between 0 and pi so I try it and results in

ValueError: substituting the piecewise variable must result in real number

So I then try to use another variable which I try to define to be 'real'


but it results in the same error... Now I try the "lambda" method since it worked when calling the plot function with the same change of variable; but fail again

integral(lambda t: phi(t/h-1),t,0,pi)
TypeError: unable to convert <function <lambda> at 0x16d71f140> to a symbolic expression

Now I try to use another integration method with definite_integral but get the same errors, only different for the "lambda" method

definite_integral(lambda x: phi(x/h-1),x,0,pi)
TypeError: cannot coerce arguments: no canonical coercion from <type 'function'> to Symbolic Ring

Is there any way around this? I really do not know what else to try...

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-03-28 20:46:53 -0500

calc314 gravatar image

This has to do with the implementation of piecewise, I think.

I can get a numerical integral to work by doing the following:


Another option would be to stop the integral at the point at which the function is zero.

edit flag offensive delete link more


@calc314 This is awesome... Had I thought about Heaviside for defining my piecewise functions, many of my problems in Sage would have been solved instantly... Thanks

jrojasqu gravatar imagejrojasqu ( 2017-03-29 13:12:57 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2017-03-28 18:28:56 -0500

Seen: 30 times

Last updated: Mar 28