-3
$\begingroup$

I am searching for an algorithm of Givens Rotation method for solving a system of linear equations. The system has this form: we start from a random matrix and random vector, this was done on MAPLE.

I don't matter if you have a code written with a different language, I will convert it to Maple's language. I really appreciate any help you can provide.

$\endgroup$

closed as off-topic by Bill Dubuque, Henrik, iadvd, Namaste, Leucippus Feb 7 '17 at 2:41

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question is not about mathematics, within the scope defined in the help center." – Bill Dubuque, Henrik, iadvd, Namaste
If this question can be reworded to fit the rules in the help center, please edit the question.

1
$\begingroup$

Here I have a code written in MATLAB which performs the QR-decomposition of a square matrix $A$ using Givens-Rotations:

function [ Q,R ] = givens ( A )
    [~,n] = size(A);
    P = eye (n);
    for i = 1:n
        for j = i+1:n
            if (A(i,i) && A(j,i)) == 0
                P_j = P;
            else
                lambda =  sqrt(A(i,i)^2 + A(j,i)^2);
                P_j = eye(n);
                P_j(i,i) = A(i,i)/lambda;
                P_j(j,j) = A(i,i)/lambda;
                P_j(i,j) = A(j,i)/lambda;
                P_j(j,i) = -A(j,i)/lambda;          
            end
            A = P_j * A;
            P = P_j * P;    
        end
    end
    R = A;
    Q = P';     
end

Now you can solve a linear system $Ax = b$ with the QR-decomposition with the following code:

function [ x ] = solvelinearsystemQR( Q,R,b )
b = Q' * b;
x = zeros(length(b),1);
for k = length(b):-1:1
    x(k,1) = (b(k) - sum(R(k,(k+1):end) * x((k+1):end,1)))/R(k,k);
end
end

since $$Ax = b \quad \Leftrightarrow \quad QRx = b \quad \Leftrightarrow \quad Rx = Q^Hb$$ and $R$ is upper triangular so elementary backwardsubstitution can be applied.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.