NSM - Trapezoidal Lab 4

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Dr D Y PatilPratishthan’s DI No.

Dr. D. Y. Patil Institute of Engineering, Management and ACAD/DI/


Research, Akurdi, Pune
Academic Unit 3. Numerical Integration Revision : 00
Year: Practical-4 Dated :
2022-2023
Date of
Term –
Department of Mechanical Engineering Preparation :
I

Name of Student #Kush Tilgule

Roll Call 20248

Program Name Program of Trapezoidal Rule

Question 1. Find the integration of (4x+2) in the limits

1 to 4 by Trapezoidal rule using six strips. 2.

Find the integration of 1 by trapezoidal rule

using
2

four strips and limits 0 to 1.1+𝑥


Code #Kush Tilgule 20248

import
math
import
numpy
as np
import
pandas
as pd

def f(x):
''' for Q.1'''
return (4*x+2) ## Function to be solved

'''for Q.2'''
#return (1/(1+(x**2))) ## Function to be solved

## Inputs
a= float(input('Enter initial
limit= ')) b=float(input('final
limit= ')) N=int(input('no. of
strips= '))
# Calculate the
trapezium step size h =
(b-a)/N
# Get the array of inputs (x-values)
X = np.linspace(a, b, N+1)

# Evaluate the function on inputs i.e


value of Y for i in X:
Y = f(X)

# Value of Integration/ Area under curve


Yn=(h/2) * (Y[0] + Y[-1] + 2*np.sum(Y[1:-1]))

table_of_output = list(zip(X, Y))

df = pd.DataFrame(table_of_output,columns=['X', 'Y=F(X)'])
print('Output') print(df) print ('Value of Integration=
',Yn)
Output Output for Q.1

Output for Q.2

Solver Output ans 1:A= 36.0 ans 2:A=


0.7827941176470589

Flowchart(Paste
Photo of Flowchart

You might also like