UPDATE:
So upon further analysis of how I defined this function in my handwritten solution, I came up with new code that seems to solve the exercise, albeit it seems a little "forced" by my standards. Based on the equations I provided above, these following transformations are done for finite time calculations:
Px = lim T→∞ (1/2T)* integral from -t1 to t2 of |x(t)|^2 dt.
Ex = integral from -t1 to t2 of |x(t)|^2 dt
Now assume my t1 and t2 are from Pos Inf to Neg Inf with intermediate values as well. By hand, this would resolve in multiple integrals with boundaries changing values (Neg Inf to -3, -3 to 0, 0 to 2 .... 5 to Pos Inf)
So that is exactly what I did. The code below is an implementation of that thought process. I am not sure if it is an optimal solution, but at least it works.
clear all
%Seperating the domain from neg inf to pos inf with
%intermediate values used for the various parts of
%the piecewise function x
tninf = -inf;
t1 = -3;
t1_2 = 0;
t2_3 = 2;
t3_4 = 4;
t4 = 5;
tpinf = inf;
syms t T
%Defining the integrals and Energies for each domain component
%each integral contains the value of x at the appropriate
%domain withing the abs() function
dninf = int(abs(0)^2,t,tninf,t1);
d1 = int(abs(cos(pi*t))^2,t,t1,t1_2);
d2 = int(abs(2)^2,t,t1_2,t2_3);
d3 = int(abs(t -1)^2,t,t2_3,t3_4);
d4 = int(abs(t + 2)^2,t,t3_4,t4);
dpinf = int(abs(0)^2,t,t4,tpinf);
Ex_ninf = dninf;
Ex1 = d1;
Ex2 = d2;
Ex3 = d3;
Ex4 = d4;
Ex_pinf = dpinf;
%Outputing the resulting Power and Energy values
Px = limit((1/2*T)*(dninf+d1+d2+d3+d4+dpinf),T,inf)
Px =
∞
Ex = Ex1 + Ex2 + Ex3 + Ex4
Ex =