MAT120 Lab Assignment
MAT120 Lab Assignment
Copying of codes from any websites or other classmates will not be tolerated.
You are ONLY ALLOWED to take help from the colab files that I have provided
but be careful NOT to copy any codes.
The outputs must be organized and readable. It must show necessary steps of
the calculation and properly display the solutions/results.
Be creative, use your intuition. Answer the questions by yourself and Do not
Cheat. Plagiarized copies will receive zero points regardless of the circum-
stances.
Total marks is 40
Deadline: 23:59 25th November, 2023
a Plot these functions and their derivatives. Include enough points so that the
curve you plot appears smooth. Use different colors and label to represent the
function and its derivative respectively. Use gray lines, one horizontal at y = 0
and the other vertical at x = 0. Limit the values of y so that the plot is
understandable. Label the axes x and y or t and y respectively.
b Use Trapezoidal rule and quad to integrate each of these functions in the given
domain. Print the results such that it shows the integral and the respective
solutions. For example,
Z 4 − 1 t2
e 2
√ dt
−4 2π
Result from Trapezoidal rule:
Result from quad:
2. Simpson’s Rule: (5+2+3 = 10)
Simpson’s 1/3 Rule is a numerical method used to approximate definite integrals.
It’s based on approximating the area under a curve using quadratic approximations.
The formula is given as
Z b
h
f (x) dx = f (a) + 4f (x1 ) + 2f (x2 ) + ... + 4f (xn−1 ) + 2f (xn−2 ) + f (b) (1)
a 3
The algorithm:
• Inputs: A function f (x), specified interval [a, b] and a value for the number of
sub-intervals N.
• Compute the width of each subinterval h : h = (b−a)
N
• Set new variables ’x i = a’ and ’sum = f(a) + f(b)’.
• Begin a loop that runs from i = 1 till i = N − 1. In each iterations, update the
value of x : x i += i*h check if i is even or odd.
• If odd then sum += 4*f(x i) otherwise if even then sum += 2*f(x i)
• Finally update sum = h/3 * sum and return the output.
1 rd
a) Implement the Simpson’s 3
rule to evaluate both of the integrals.
b) Evaluate both integrals using the package scipy.integrate and show both result
and the error separately as outputs keeping atleast six decimal places.
c) Use sympy to solve both the integrals symbolically without the limits. Plot
the resulting functions in a single graph and label each function correctly using
legends to show it on the plot.
where
Z z Z z
2
sin x2 dx
C(z) = cos x dx S(z) =
0 0
Carry out these integrals numercially (Using any preferred algorithm e.g. Trapezoidal
Rule or Monte Carlo) for values of z ∈ [0, 20] and generate a parametric plot S vs C.
The graph plotted is known as the Cornu Spiral.
x2
f (x) = exp(x) sin(x) − +5
2
for −1 ≤ x ≤ 3.
(EVALUATE THE FIRST AND SECOND DERIVATIVES TO FIND THE
DESIRED EXTREMA)
Special Functions:
Write a function named Beta(x, y) that takes x and y as arguments and returns the
result of the integral.
(a) Evaluate β 5, 4). (2)
Write a function named Gamma(n) that takes n as an argument and returns the
result of the integral. (Use mathinf by using import math)
√
(a) Show that Γ 21 = π. (2)
(b) Find Γ 72 . Provide both rational and decimal output.
(1)