function [xvals,muvals]=powermethod(A,x,numtimes,tol)

xvals = [];
muvals = [];

for r=1:numtimes 
    
  x = A*x;

  [maxval,maxnr]=max(abs(x));
  mu = x(maxnr); 
  x = (1/mu)*x;
                % Kunne her brukt R = x'*A*x/(x'*x) i stedet for mu

  muvals = [muvals mu]; 
  xvals = [xvals x];

  error = max(abs(A*x-mu*x));
  if error<tol

  break; 
  end
end