Question

Using the trapezium rule, we can calculate the integral of a function, f(x), between the limits of x=a and x=b to be approximately : \int_{a}^{b} f(x) d x=\frac{h}{2}\left[f(a)+f(b)+2 \sum_{i=1}^{n-1} f(a+i

h)\right] \text { Write a program to calculate the integral of } \sin ^{2}(x) \text {. } Your program should : Ask the user for the values of a, b and how many points between these values. Use the inline command in the script to evaluate sin²(x) when calculating the integral. \text { - Be tested using the information that } \int_{0}^{\pi} \sin ^{2}(x) d x=\frac{\pi}{2} The error function, erf(z), is used in solving the heat equation. It is given by : \operatorname{erf}(z)=\frac{2}{\sqrt{\pi}} \int_{0}^{z} e^{-x^{2}} d x Write a program which will calculate the value of the erf(z), adapted from your trapezium integrationprogram above. You can test you program using the information that erf(1) = 1.

Fig: 1

Fig: 2

Fig: 3

Fig: 4

Fig: 5

Fig: 6

Fig: 7

Fig: 8

Fig: 9

Fig: 10

Fig: 11