Gaussian Elimination: Time Complexity and Method with Partial Pivoting, Assignments of Mathematics for Computing

The process of measuring the time taken for basic arithmetic operations (addition, multiplication, and division) on a computer and implementing the gaussian elimination method with partial pivoting using python. A code snippet for the gaussian elimination method and explains how to calculate the time taken for each operation.

Typology: Assignments

2021/2022

Uploaded on 04/19/2022

deysandip81
deysandip81 🇮🇳

3 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Q1)$Implementing$Gaussian$Elimination$Method$
i) Find$the$approximate$time$your$computer$takes$for$a$single$addition$by$adding$
first$106"positive$integers$using$a$for$loop$and$dividing$the$time$taken$by$106.$
Similarly$find$the$approximate$time$taken$for$a$single$multiplication$and$division.$
Report$the$result$obtained$in$the$form$of$a$table.$(
Deliverable(s):-A-tabular-column-indicating-the-time-taken-for-each-of-the-
operations--
Answer:$
Time taken for Addition(in
Sec)
Time taken for Multiplication(in
Sec)
Time taken for Division(in
Sec)
9.656799999999998e-08
PS: Total is
0.09656799999999999
0.00037666722
PS: Total is 376.66722
0.0003767326
PS: Total is 376.7326
ii) Deliverable(s):-The-code-for-the-Gaussian-elimination-with-and-with--out-partial-
pivoting-with-the-rounding-part-!
Answer:$
Code: GIT Link :
https://github.com/deysandip81/BITS_MTECH_Projects/blob/main/GaussElimination
.py
import numpy as np
# defining a function for
# round s.
def round_s(n, decimals=0):
if decimals == 0:
n_5s = n + 5 * pow(10, -(decimals+1))
else:
n_5s = n + 5 * pow(10, -(decimals))
if '.' in str(n_5s) and '-' in str(n_5s):
return(float(str(n_5s)[0:decimals+2]))
elif '.' in str(n_5s) or '-' in str(n_5s):
return (float(str(n_5s)[0:decimals + 1]))
else:
return (float(str(n_5s)[0:decimals]))
def Cal_LU(D,g,ds):
A=np.array((D),dtype=float)
f=np.array((g),dtype=float)
num_add = 0
num_sub = 0
num_div = 0
num_mult = 0
n = f.size
for i in range(0,n-1): # Loop through the columns of the matrix
for j in range(i+1,n): # Loop through rows below diagonal for each
column

Partial preview of the text

Download Gaussian Elimination: Time Complexity and Method with Partial Pivoting and more Assignments Mathematics for Computing in PDF only on Docsity!

Q1) Implementing Gaussian Elimination Method

i) Find the approximate time your computer takes for a single addition by adding

first 10^6 positive integers using a for loop and dividing the time taken by 106.

Similarly find the approximate time taken for a single multiplication and division.

Report the result obtained in the form of a table. (

Deliverable(s): A tabular column indicating the time taken for each of the

operations

Answer:

Time taken for Addition(in

Sec)

Time taken for Multiplication(in

Sec)

Time taken for Division(in

Sec)

PS: Total is

PS: Total is 376.

PS: Total is 376.

ii) Deliverable(s): The code for the Gaussian elimination with and with- out partial

pivoting with the rounding part

Answer:

Code: GIT Link :

https://github.com/deysandip81/BITS_MTECH_Projects/blob/main/GaussElimination

.py

import numpy as np

defining a function for

round s.

def round_s(n, decimals= 0 ): if decimals == 0 : n_5s = n + 5 * pow( 10 , - (decimals+ 1 )) else: n_5s = n + 5 * pow( 10 , - (decimals)) if '.' in str(n_5s) and '-' in str(n_5s): return(float(str(n_5s)[ 0 :decimals+ 2 ])) elif '.' in str(n_5s) or '-' in str(n_5s): return (float(str(n_5s)[ 0 :decimals + 1 ])) else: return (float(str(n_5s)[ 0 :decimals])) def Cal_LU(D,g,ds): A=np.array((D),dtype=float) f=np.array((g),dtype=float) num_add = 0 num_sub = 0 num_div = 0 num_mult = 0 n = f.size for i in range( 0 ,n- 1 ): # Loop through the columns of the matrix for j in range(i+ 1 ,n): # Loop through rows below diagonal for each column