clear all
clc

x = -5/2:.01:5/2;
n = length(x);
f = zeros(1,n);

for i = 1:n
    if (x(i) >= -5/2) && (x(i) < -3/2)
        f(i) = (1/24)*(x(i) + 5/2)^4;
    elseif (x(i) >= -3/2) && (x(i) < -1/2)
        f(i) = (1/24)*(1 +4*(x(i)+3/2) + 4*(x(i)+3/2)^3 + 6*(x(i)+3/2)^2 - ...
            (x(i)+3/2)^4);
    elseif (x(i) >= -1/2) && (x(i) < 1/2)
        %f(i) = (1/24)*(1 + 4*(1/2-x(i)) + 4*(1/2-x(i))^3 + 6*(1/2-x(i))^2 - ...
         %   (1/2-x(i))^4);
         %f(i) = 1-1.4168*x(i)^2 - x(i)^4;
         f(i) = 1 - 2.83333333*x(i)^2 + 4.66666667*x(i)^4;
    elseif (x(i) >= 1/2) && (x(i) < 3/2)
        f(i) = (1/24)*(1 + 4*(3/2-x(i)) + 4*(3/2-x(i))^3 + 6*(3/2-x(i))^2 - ...
            (3/2-x(i))^4);
    elseif (x(i) >= 3/2) && (x(i) < 5/2)
        f(i) = (1/24)*((5/2-x(i))^4);
    else
        f(i) = 0;
    end
end

plot(x,f)

            
        
        

