function [Jacw]=Jacobiw(k,A,N,w)
    
    D=diag(diag(A))
    L=tril(A)-D
    U=triu(A)-D
    b=A*ones(N,1)
     
     if k==0 then Jacw=zeros(N,1)
        else Jacw=[(1-w)*diag(ones(1,N))-w*inv(D)*(L+U)]*Jacobiw(k-1,A,N,w)+w*inv(D)*b
    end
endfunction

function [Lambw]=Spectw(A,N,w)
    D=diag(diag(A))
    L=tril(A)-D
    U=triu(A)-D
    Rjw=(1-w)*diag(ones(1,N))-w*inv(D)*(L+U)
    Lambw=abs(spec(Rjw))
    Lambw=gsort(Lambw)
endfunction

function [LambM1]=RSpecw1(Lambw)
    LambM1=Lambw(N)    
endfunction

function [LambMN]=RSpecwN(Lambw)
    LambMN=Lambw(1)    
endfunction

function [w]=Val(LambM1,LambMN)
    w=2/(2-LambM1-LambMN)
endfunction