function [xp,fp] = ffd(x,y,n)
% Computes the nth derivate of y(x) using forward finite difference
% using the basic formula O(h)
% n can be from 1 to 4
% assumes equal spaces between x-values

h = x(2)-x(1);
switch n
    case 1
        fp = (y(2:end)-y(1:end-1))./h;
        xp = x(1:end-1);
    case 2
        fp = (y(3:end)-2.*y(2:end-1)+y(1:end-2))./(h.^2);
        xp = x(1:end-2);
    case 3
        fp = (y(4:end)-3.*y(3:end-1)+3.*y(2:end-2)-y(1:end-3))./(h.^3);
        xp = x(1:end-3);
    case 4
        fp = (y(5:end)-4.*y(4:end-1)+6.*y(3:end-2)-4.*y(2:end-3)+y(1:end-4))./(h.^4);
        xp = x(1:end-4);
end