%This function allows for cubic spline interpolation of the value function at
%points between the grid points.
function[fxhat]=valuecub(kgrid,v0,ki,x)
global eta alpha beta delta
ck=ki^alpha+(1-delta)*ki-x; %consumption for the grid i capital
uk=utilchp4(ck,eta); %utility at choice x for kt+1
[fx]=spline(kgrid,v0,x); %cubic spline interpolation of value function 
fxhat=uk+beta*fx; %cubic spline interpolated value function