Evaluating Programming Problem 11 for user aboda
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  5.180694e-18. 
> In aboda_hbommaka_pp11 (line 35)
In eas501_pp13_unit
 
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  3.316886e-18. 
> In aboda_hbommaka_pp11 (line 35)
In eas501_pp13_unit
 
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  5.327833e-19. 
> In aboda_hbommaka_pp11 (line 35)
In eas501_pp13_unit
 
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  8.073775e-19. 
> In aboda_hbommaka_pp11 (line 35)
In eas501_pp13_unit
 
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  3.333546e-18. 
> In aboda_hbommaka_pp11 (line 35)
In eas501_pp13_unit
 
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  7.660842e-19. 
> In aboda_hbommaka_pp11 (line 35)
In eas501_pp13_unit
 
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  1.438608e-18. 
> In aboda_hbommaka_pp11 (line 35)
In eas501_pp13_unit
 
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  6.703444e-19. 
> In aboda_hbommaka_pp11 (line 35)
In eas501_pp13_unit
 
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  4.835544e-18. 
> In aboda_hbommaka_pp11 (line 35)
In eas501_pp13_unit
 
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  1.434842e-17. 
> In aboda_hbommaka_pp11 (line 35)
In eas501_pp13_unit
 
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  5.528399e-19. 
> In aboda_hbommaka_pp11 (line 35)
In eas501_pp13_unit
 
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  6.068592e-19. 
> In aboda_hbommaka_pp11 (line 35)
In eas501_pp13_unit
 
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  1.617341e-18. 
> In aboda_hbommaka_pp11 (line 35)
In eas501_pp13_unit
 
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  1.719356e-18. 
> In aboda_hbommaka_pp11 (line 35)
In eas501_pp13_unit
 
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  5.984544e-18. 
> In aboda_hbommaka_pp11 (line 35)
In eas501_pp13_unit
 
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  4.333286e-18. 
> In aboda_hbommaka_pp11 (line 35)
In eas501_pp13_unit
 
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  1.644754e-18. 
> In aboda_hbommaka_pp11 (line 35)
In eas501_pp13_unit
 
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  9.459028e-18. 
> In aboda_hbommaka_pp11 (line 35)
In eas501_pp13_unit
 
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  1.259196e-18. 
> In aboda_hbommaka_pp11 (line 35)
In eas501_pp13_unit
 
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  3.408247e-18. 
> In aboda_hbommaka_pp11 (line 35)
In eas501_pp13_unit.  No If make chnages to v= inv(M) * v  my test cases are not satisfied. Come with a work around for this with a new approach for this problem.function [l, v] = aboda_hbommaka_pp11(A, v0, tol, itermax)
% ABODA_HBOMMAKA_pp11 - This function implements the Rayleigh-Quotient iteration for eigenvalue and eigenvector calculation.
%
% Input:
%   A - Real and square matrix.
%   v0 - Initial vector.
%   tol - Tolerance for convergence.
%   itermax - Maximum number of iterations.
%
% Output:
%   l - Resulting eigenvalue.
%   v - Associated eigenvector.


    % Initialize variables
    
    
    % Initialize variables
    v = v0;
    n = size(A,1);
    l = 0;
    iter = 0;
    converged = false;
    
    % Loop until convergence or maximum iterations reached
    while ~converged && iter < itermax
        % Update eigenvalue
        l_previous = l;
        l = dot(v, A * v) / dot(v, v);
        
        % Update eigenvector
        M = (A - l * eye(n));
        if rcond(M) < 1e-15 % check if M is close to singular
            v = M \ v;
        else
            v = inv(M) * v;
        end
        v = v / norm(v);
        
        % Check convergence
        converged = (abs((l-l_previous)/l) < tol);
    
        % Increment iteration count
        iter = iter + 1;
    end
    
    % Check if maximum iterations reached
    if iter >= itermax && ~converged
        error('Maximum number of iterations exceeded');
    end
end % aboda_hbommaka_pp11