Write a program that calculates the integral from a to b of

Write a program that calculates the integral from a to b of the function f(x) = x^2 + 1 with the following ways: A serial program in which a, b, n are given by the user. A parallel program in which a, b, n are defined inside the code (a = 0.0, b = 3.0, n = 1024). A parallel program in which a, b, n are given by the user.

Solution

First I\'ll write an algorithm or steps to write the program for integration :

Step 1 Set h = (b - a)/n.
Step 2 Set XI 0 = f(a) + feb);
XI 1 = 0; (Summation of f(x2i-1).)
X I2 = O. (Summation of f (X2i)\')
Step 3 For i = 1, ... ,n - 1 do Steps 4 and 5.
Step 4 Set X = a + ih.
Step 5 If i is even then set XI2 = X/2 + f(X)
else set XIl = XIl + f(X).
Step 6 Set XI = h(XIO + 2· XI2 + 4· XIl)/3.
Step 7 OUTPUT (Xl);
STOP.

1 ) The below function computes integral of a function from a to b with a and b inclusive: in which a,b,n are given by user

}

2) A parellel program in which a,b,n are defined inside the code :

}

3) For a parellel program , Each core uses it’s own private variables and executes this block of code independently of the other cores.

}

 Write a program that calculates the integral from a to b of the function f(x) = x^2 + 1 with the following ways: A serial program in which a, b, n are given by

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site