function M_R = Mem_Radiation(body,RB,n,L)

frac = mod(n,1);
n = floor(n);

M_R = zeros(1,6);

if (n < 2)
    return;
end

dt = get(body,'dt');
xddot = get(body,'xddot');


if (isstruct(L{1,1}) == 0)
  tau = 0:dt:dt*(length(L{1,1})-1);
else
    %tau = 0:dt:dt*(L{1,1}.pieces);
    tau = 0:dt:L{1,1}.breaks(end);
end

NN = min(n,length(tau));

Integrand = zeros(1,NN);

for i = 1:6
  M_R(i) = 0;  
  for j = 1:6
      if (isstruct(L{i,j}) == 0)
         j
         L{i,j} = interp1(tau,L{i,j},'spline','pp');  %Convert only if coefficient structure not passed.
      end
        L_loc = L{i,j};
        L_loc = ppval(L_loc,tau+dt*frac);
               
      for nn = 1:NN
     
      Integrand(nn) = xddot(n-nn+1,j)*L_loc(nn);
      end
      
    M_R(i) = M_R(i) - dt*(sum(Integrand)-.5*Integrand(1)-.5*Integrand(end));
    
  end
end
  
