% Liang,Qian 807755  Luo,Xi 810103   Zhong,Mingzhi 766377
function [] = prog1main()
m=input('enter m  ')
n=input('enter n  ')
if (n<=0 | m<=n)
    break
end

%def.A 
for i= 1:m
   for j = 1:n 
       if(i==j)
         A(i,j)=2;
       end  
       if(i<=n)
         if (1==abs(i-j))
          A(i,j)=1;
         end 
       else
           A(i,j)=0;
       end 
   end 
end

%def.b
for k=1:m
    if (k==1 | k==m)
        b(k)=3;
    else b(k)=4;
    end
end   
disp(A)
disp(b)

%Givens-Rotationen
for i=1:(n-1)
    r=sqrt(A(i,i)^2+A(i+1,i)^2);
    c=A(i,i)/r;
    s=A(i+1,i)/r;
    
    t=b(i);
    b(i)=c*t+s*b(i+1);
    b(i+1)=-s*t+c*b(i+1);
    
    for k=i:n
        p=A(i,k);
        q=A(i+1,k);
        A(i,k)=c*p+s*q;
        A(i+1,k)=-s*p+c*q;
    end
end   

%Rueckwaertsub.
x(n)=b(n)/A(n,n);
for i=(n-1):-1:1
      add=A(i,i+1:n)*x(i+1:n)';
      x(i)=(b(i)-add)/A(i,i);
end 
disp(A)
disp(b)
disp(x)
return
 