Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Short answer

You can rewite $g$ as $$g(w)=(w-3)^2(H(w)-H(w-3)),$$ where $H$ stands for the Heaviside function, given by $$H(x)=\begin{cases} 0, & x<0, \\\\ 1, & x>0. \end{cases}$$

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)=g_0(x)$ in $(-\infty,x_0)$, $g(x)=g_i(x)$ in $(x_{i-1},x_i)$ for $i=1,\ldots,k$, and $g(x)=g_{k+1}(x)$ in $(x_k,+\infty)$, we have: $$g(x) =g_0(x) + \sum_{i=0}^k \bigl(g_{i+1}(x)-g_i(x)\bigr) H(x-x_i).$$ The values of $g$ at $x_0,...,x_k$ are not relevant, since we are dealing with integration.

In the original question, we have $k=1$, $x_0=0$, $x_1=3$, $g_0(x)=0$, $g_1(x)=(x-3)^2$ and $g_2(x)=0$. Therefore, $$g(x)\begin{aligned}[t] &=g_0(x)+(g_1(x)-g_0(x))H(x-x_0) + (g_2(x)-g_1(x))H(x-x_1) \\ &= (x-3)^2H(x)-(x-3)^2H(x-3) \\ &=(x-3)^2(H(x)-H(x-3)). \end{aligned}$$ This justifies the code given above.

Short answer

You can rewite rewrite $g$ as $$g(w)=(w-3)^2(H(w)-H(w-3)),$$ where $H$ stands for the Heaviside function, given by $$H(x)=\begin{cases} 0, & x<0, \\\\ 1, & x>0. \end{cases}$$

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)=g_0(x)$ in $(-\infty,x_0)$, $g(x)=g_i(x)$ in $(x_{i-1},x_i)$ for $i=1,\ldots,k$, and $g(x)=g_{k+1}(x)$ in $(x_k,+\infty)$, we have: $$g(x) =g_0(x) + \sum_{i=0}^k \bigl(g_{i+1}(x)-g_i(x)\bigr) H(x-x_i).$$ The values of $g$ at $x_0,...,x_k$ are not relevant, since we are dealing with integration.

In the original question, we have $k=1$, $x_0=0$, $x_1=3$, $g_0(x)=0$, $g_1(x)=(x-3)^2$ and $g_2(x)=0$. Therefore, $$g(x)\begin{aligned}[t] &=g_0(x)+(g_1(x)-g_0(x))H(x-x_0) + (g_2(x)-g_1(x))H(x-x_1) \\ &= (x-3)^2H(x)-(x-3)^2H(x-3) \\ &=(x-3)^2(H(x)-H(x-3)). \end{aligned}$$ This justifies the code given above.