Skip to content

Instantly share code, notes, and snippets.

@accessnash
Created December 30, 2019 20:07
Show Gist options
  • Select an option

  • Save accessnash/28f8a6b9ba0c36879f350763c353cc8b to your computer and use it in GitHub Desktop.

Select an option

Save accessnash/28f8a6b9ba0c36879f350763c353cc8b to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 30 21:00:52 2019
@author: DASA0
"""
""" find the value of the integral xsinx from 0 to pi/2"""
from math import sin, pi
f = lambda x: x*sin(x)
a = 0
b = pi/2
n = 16
h = (b - a) /n
S = 0.5*(f(a) + f(b))
for i in range(1, n):
S += f(a + i*h)
integral = h * S
print('Integral = %f' % integral)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment