(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
Gauss Elimination (With Partial Pivot)
1. PRACTICAL
Name- Saloni Singhal
M.Sc. (Statistics) II-Sem.
Roll No: 2046398
Course- MATH-409 L
Numerical Analysis Lab
Submitted To: Dr. S.C. Pandey
2. OBJECTIVE
• To write an m-file to implement Gauss
elimination method with partial pivoting for
solving system of linear equations.
• To write both script and function files for the
same program.
3. Theory
In partial pivoting in Gaussian elimination, the algorithm selects the entry
with largest absolute value from the column of the matrix that is currently
being considered as the pivot element.
b. Interchange the rows such that the pivot comes to the first row.
c. Divide the first row by the pivot to make it 1.
d. Use elementary row operations (row only) to reduce the other elements
in the column of this pivot to 0 (with the pivot still being held at 1).
These four steps together is called a pass. (First Pass)
Now ignoring the column and row of the pivot and considering co-factor
submatrix of the pivot, repeat the pivot operations. Repeat these process.
At the end of the two passes, the full matrix would be in the row echelon
form and by back substitution, we determine the values of the unknowns
Advantage:
Partial pivoting is generally sufficient to adequately reduce round-off error
and save time/ storage space in sparse matrix.
4. Script File
function x =guass_ppivot(A,b)
[m n]=size(A);
if m~=n
fprintf("incorrect size")
exit
end
aug=[A b]
for i=1:m-1 %choosing pivot element and row exchange
[val pos] = max(aug(i:n,i)); %value and position
pos=pos+i-1;
temp=aug(i,:); %storing matrix for swapping
aug(i,:)=aug(pos,:);
aug(pos,:)=temp;
for j=i+1:m %forward elimination
a=aug(j,i)/aug(i,i);
aug(j,:)=aug(j,:)-a*aug(i,:);
end
end
x(n)=aug(n,n+1)/aug(n,n);
for i=n-1:-1:1 %backward substitution
x(i)=(aug(i,n+1)-dot(aug(i,i+1:n),x(i+1:n)))/aug(i,i);
end
end
5. Function File
function x =guass_script(A,b)
[m n]=size(A);
if m~=n
fprintf("incorrect size")
exit
aug=[A b]
for i=1:m-1 %choosing pivot element and row exchange
[val pos] = max(aug(i:n,i)) %value and position
pos=pos+i-1
temp=aug(i,:)
aug(i,:)=aug(pos,:)
aug(pos,:)=temp
for j=i+1:m %forward elimination
a=aug(j,i)/aug(i,i)
aug(j,:)=aug(j,:)-a*aug(i,:)
end
end
x(n)=aug(n,n+1)/aug(n,n)
for i=n-1:-1:1 %backward substitution
x(i)=(aug(i,n+1)-dot(aug(i,i+1:n),x(i+1:n)))/aug(i,i)
end
end
7. Time Complexity
7
For the given program it is calculated as:
For i=1 T(j)= Σ(n+2-1)
For i=2 T(j)= T((2n3+n2-3n)/2) =O(n3)
T(n)=(n+2)(n-1)-n(n-1)/2= O(n2)
For calculating maximum= O(n)
on summation since in square matrix m=n, =O(n3)
Which the dominant value of all the calculated time
complexities.
Big O notation is the most common metric for calculating time complexity. It
describes the execution time of a task in relation to the number of steps
required to complete it.
We calculate the
no of operations in
two respective
loops.
Big ‘O’ notation
takes its dominant
value
8. Conclusion
Gaussian elimination provides algorithm that
calculate exact arithmetic and computes the solution
with finite number of elementary operations,
however linear system of equation represents an
exceptional case as it is hardly possible to solve
general system using only finite number of
elementary operations such as the irrational
numbers. Thus, we need iterative methods to solve
system of linear equations.
9. Caveats
Using partial pivoting has a little bit fewer
options of what to choose from, so it can yield
inferior solutions in some cases. Partial pivoting
adds row permutation (or equation permutation)
and full pivoting will add row
and column permutation (column permutation
corresponds to variable or solution vector
permutation) so it gives more stable solutions.