reverse-shooting

Matlab scripts for reverse shooting
Log | Files | Refs | README

interplin4.m (802B)


      1 function newy=interplin(y,x,newx)
      2 
      3 % interplin4
      4 %     function newy=interplin(y,x,newx)
      5 %
      6 %   Simple linear interpolation, assuming that x is monotone
      7 %
      8 %     y = Variable to be interpolated  -- Nx1
      9 %     x = Values we know, corresponding to existing y -- Nx1
     10 %   newx = x values for which we need y values (can include x)
     11 %                    1960 10
     12 %                    1965 15
     13 %                    1967 14
     14 %
     15 %    newy=interplin(y,x,[1962; 1966]) will return [12; 14.5]
     16 
     17 
     18 newy=zeros(length(newx),1);
     19 for i=1:length(newx);
     20    lessthan=find(x<=newx(i));
     21    greatthan=find(x>=newx(i));
     22    jlow=max(lessthan);
     23    jhigh=min(greatthan);
     24    if jlow==jhigh; 
     25       newy(i)=y(jlow); 
     26    else;
     27       dx=x(jhigh)-x(jlow);
     28       dy=y(jhigh)-y(jlow);
     29       newy(i)=y(jlow)+dy/dx*(newx(i)-x(jlow));
     30    end;
     31 end;
     32