
// Question 1

function y=li(LX,i,x)
    y=1
    for j=1:length(LX)
        if j <> i
            y=y*(x-LX(j))/(LX(i)-LX(j))
        end
    end
endfunction

// Question 2
// l_i'(x_i) = sum_{j=1, j <> i}^n 1/(x_i-x_j)

function y=lider(LX,i)
    y=0
    for j=1:length(LX)
        if j <> i
            y=y+1/(LX(i)-LX(j))
        end
    end
endfunction

// Question 3

function S=hermite(LX,F,FP,T)
    S=[]
    for k=1:length(T)
        s=0
        for i=1:length(F)
            s=s+(1-2*(T(k)-LX(i))*lider(LX,i))*li(LX,i,T(k))^2*F(i)+(T(k)-LX(i))*li(LX,i,T(k))^2*FP(i)
        end
        S=[S,s]
    end
endfunction

// Question 4

function s=b(T,i,n,t)
    if n==0
        s=0
        if T(i) <= t & t < T(i+1)
            s=1
        end
    else
        s=(t-T(i))/(T(i+n)-T(i))*b(T,i,n-1,t)+(T(i+n+1)-t)/(T(i+n+1)-T(i+1))*b(T,i+1,n-1,t)
    end
endfunction

function S=bspline(T,P,m,n,L)
    S=[]
    for k=1:length(L)
        s=0
        for i=1:m-n-1
            s=s+b(T,i,n,L(k))*P(:,i)
        end
        S=[S,s]
    end
    
endfunction

