Integration Drill: In Class 2.14

  1. \(\int_0^3 3x^5 - x + 7 ~ dx\)
In [1]:
import sympy as sy
In [5]:
x = sy.Symbol('x')
f = 3*x**5 - x + 7
a = 0
b = 3
area = sy.integrate(f, (x, a, b))
print('The area under the curve', f, 'from', a, 'to', b, 'equals', area)
The area under the curve 3*x**5 - x + 7 from 0 to 3 equals 381

All in One with Scipy Quad Integration Function

In [24]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
from scipy.integrate import quad

def f(x):
    return 3*x**5 - x + 7

a = 0
b = 3
x = np.linspace(a, b, 1000)
area = quad(f, a, b)
plt.plot(x, f(x))
plt.fill_between(x, f(x), alpha = 0.2, color = 'grey')
plt.title('Area Under $f(x) = 3x^5 - x + 7$', loc = 'left', size = 14)
plt.text(0, 600, ('The area is equal to ', format(area[0], '0.2f')))
Out[24]:
Text(0,600,"('The area is equal to ', '381.00')")
_images/12-Integral-Drill_4_1.png

Problem II

In [35]:
x = sy.Symbol('x')
f = 3*sy.sin(x) - 0.5*sy.cos(x)
a = -2*sy.pi
b = 4*sy.pi
area = sy.integrate(f, (x, a, b))
print('The area under the curve', f, 'from', a, 'to', b, 'equals', area)
The area under the curve 3*sin(x) - 0.5*cos(x) from -2*pi to 4*pi equals 0
In [36]:
def f(x):
    return 3*np.sin(x) - 0.5*np.cos(x)

a = -2*np.pi
b = 4*np.pi
x = np.linspace(a, b, 1000)
area = quad(f, a, b)
plt.plot(x, f(x))
plt.fill_between(x, f(x), alpha = 0.2, color = 'grey')
plt.title('Area Under $f(x) = 3\sin{x} - 0.5\cos{x}$', loc = 'left', size = 14)
print('The area under f(x) is equal to ', format(area[0], '0.2f'))
The area under f(x) is equal to  -0.00
_images/12-Integral-Drill_7_1.png

Problem 3

In [37]:
x = sy.Symbol('x')
f = 5/x -2*sy.exp(x)
a = 1
b = 2*sy.pi
area = sy.integrate(f, (x, a, b))
print('The area under the curve', f, 'from', a, 'to', b, 'equals', area)
The area under the curve -2*exp(x) + 5/x from 1 to 2*pi equals -2*exp(2*pi) + 2*E + 5*log(2*pi)

Problem 4

In [12]:
x = sy.Symbol('x')
f = 3*sy.cos(x**2) - sy.exp(x)*sy.log(x)
a = 5
b = 7
area = sy.integrate(f, (x, a, b))
print('The area under the curve', f, 'from', a, 'to', b, 'equals', area)
The area under the curve -exp(x)*log(x) + 3*cos(x**2) from 5 to 7 equals -exp(7)*log(7) - Ei(5) - 3*sqrt(2)*sqrt(pi)*fresnelc(5*sqrt(2)/sqrt(pi))*gamma(1/4)/(8*gamma(5/4)) + 3*sqrt(2)*sqrt(pi)*fresnelc(7*sqrt(2)/sqrt(pi))*gamma(1/4)/(8*gamma(5/4)) + Ei(7) + exp(5)*log(5)