%Problem u3.2 solved by Gaussian elimination and by LU-decomposition
%Stiffness matrix
a=[1 1/2 1/3;1/2 1/3 1/4;1/3 1/4 1/5]
%multiple load vectors
b=[3 2.9 3.1 3.0 3.0;1.9 2.0 1.8 2.0 1.9167; 1.433 1.500 1.400 1.400 1.4333];
b1=b(:,1)
b2=b(:,2)
b3=b(:,3)
b4=b(:,4)
b5=b(:,5)
%Gausian Elinination
flops(0)
%problem 1
[ua,ba]=ge2piv(a,b1);
xga=bsub1(ua,ba);
%problem 2
[ub,bb]=ge2piv(a,b2);
xgb=bsub1(ub,bb);
%problem 3
[uc,bc]=ge2piv(a,b3);
xgc=bsub1(uc,bc);
%problem 4
[ud,bd]=ge2piv(a,b4);
xgd=bsub1(ud,bd);
%problem 5
[ue,be]=ge2piv(a,b5);
xge=bsub1(ue,be);
flopsge=flops
%LU Decomposition
flops(0)
%factorize matrix
[l u p]=lu(a);
%problem 1
ya=fsub1(l,p*b1);
xlua=bsub1(u,ya);
%problem 2
yb=fsub1(l,p*b2);
xlub=bsub1(u,yb);
%problem 3
yc=fsub1(l,p*b3);
xluc=bsub1(u,yc);
%problem 4
yd=fsub1(l,p*b4);
xlud=bsub1(u,yd);
%problem 5
ye=fsub1(l,p*b5);
xlue=bsub1(u,ye);
flopslu=flops
% compare results
[xga xlua xgb xlub xgc xluc xgd xlud xge xlue]



