Processing math: 100%
Ask Your Question
1

Integration of multivariable piecewise function in SageMath

asked 4 years ago

J. Serra gravatar image

I have a problem that can be simplified as below:

g(w) = piecewise([[[0, 3], (w-3)^2], [(3, infinity), 0]])  
f(w,t) = g*cos(w*t)  # t >= 0
#assume(t, 'real')  
h = integral(f, w, 0, 10); h

Out: t |--> undef

If I do not use piecewise, and integrate only up to w = 3 (where I know g becomes zero), then I obtain the wanted solution:

g2(w) = (w-3)^2
f2(w, t) = g2*cos(w*t)
h2 = integral(f2, w, 0, 3); h2

Out: t |--> 6/t^2 - 2sin(3t)/t^3

How can I integrate f(w, t) defining g(w) piece-wisely (or equivalent)?

Preview: (hide)

Comments

Welcome to Ask Sage! Thank you for your question!

slelievre gravatar imageslelievre ( 4 years ago )

1 Answer

Sort by » oldest newest most voted
2

answered 4 years ago

Juanjo gravatar image

updated 4 years ago

Short answer

You can rewrite g as g(w)=(w3)2(H(w)H(w3)), where H stands for the Heaviside function, given by H(x)={0,x<0,1,x>0.

Then, the following code solves the question:

sage: g(w) = (w-3)^2*(heaviside(w) - heaviside(w-3))
sage: f(w,t) = g(w)*cos(w*t)
sage: integral(f(w,t), w, 0, 10, algorithm="giac")
6/t^2 - 2*sin(3*t)/t^3

It seems that Maxima and Sympy cannot integrate functions involving translates of H, but Giac can do it. This is why I added the option algorithm="giac".

Explanation

Any piecewice function g can be written in terms of translates of the Heavide function. Assuming that g(x)=g0(x) in (,x0), g(x)=gi(x) in (xi1,xi) for i=1,,k, and g(x)=gk+1(x) in (xk,+), we have: g(x)=g0(x)+ki=0(gi+1(x)gi(x))H(xxi). The values of g at x0,...,xk are not relevant, since we are dealing with integration.

In the original question, we have k=1, x0=0, x1=3, g0(x)=0, g1(x)=(x3)2 and g2(x)=0. Therefore, g(x)=g0(x)+(g1(x)g0(x))H(xx0)+(g2(x)g1(x))H(xx1)=(x3)2H(x)(x3)2H(x3)=(x3)2(H(x)H(x3)). This justifies the code given above.

Preview: (hide)
link

Comments

Thanks @Juanjo, this is a good alternative definition and solves my problem. Would be good to understand what is wrong with piecewise

J. Serra gravatar imageJ. Serra ( 4 years ago )

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 4 years ago

Seen: 995 times

Last updated: Jan 17 '21