Starting from:
$35

$29

Assignment 3 Solution

1. Write a real Fortran function SERIES(X) which returns an approximate sum of the sequence

x   x2
x3     x4



+




+···
1!

2!


3!

4!


i.e., which adds consecutive elements of this sequence until the addition of another term does not change the value of the sum.

Write also a Fortran program which reads consecutive values x and uses the function SERIES to find the approximate sum for each of these values. Assume that the value 0 indicates the end of data.

    2. The secant method of finding a root of a continuous function f (x) (i.e., solving the equation f (x) = 0) uses two initial values a and b which are “close” to the solution. In each iteration step an approximation x to the solution is determined by the straight line (the secant line) defined by the points (a, f (a)) and (b, f (b)), so:

        ◦ (b)
x = b − (b − a) f (b) − f (a)


The iteration continues using the most recent approximation x and b as the pair for the next iteration, so actually:


xI = xI−1 − (xI−1 − xI−2) f (xI−1) − f (xI−2)


where x0 = b and x−1 = a. The iteration ends when two consecutive approximations are sufficiently close (i.e., when they differ by less than a small value ε).

Write a Fortran function Secant(a, b, eps, limit, iter) which finds the root of a function f un(x) using the secant method. limit is the limit on the number of iteration steps - the secant method can be non-convergent, especially when the initial values a and b are not close to the solution. iter returns the number of iterations used for finding the solution. Use several values of a and b to see how these values affect the required number of iterations.

More products