Ask Your Question
0

Integrate piecewise function with change of variable

asked 2017-03-29 01:28:56 +0100

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); 
h=pi/n;
h=h.n();

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

integral(phi(x/h-1),x,0,pi)
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'

t=var('t')
assume(t,'real');
integral(phi(t/h-1),t,0,pi)

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
0

answered 2017-03-29 03:46:53 +0100

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:

phi(x)=(heaviside(x+1)-heaviside(x-1))*(1-abs(x))*(1-abs(x))*(1+2*abs(x))
numerical_integral(phi(x/h-1),0,pi)

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

phi2(x)=(1-abs(x))*(1-abs(x))*(1+2*abs(x))
integral(phi2(x/h-1),x,0,2*pi/n)
edit flag offensive delete link more

Comments

@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 20:12:57 +0100 )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

Stats

Asked: 2017-03-29 01:28:56 +0100

Seen: 970 times

Last updated: Mar 29 '17