Fortran Program For Secant Method Numerical
I am trying to write a program to solve for pipe diameter for a pump system I've designed. I've done this on paper and understand the mechanics of the equations. I would appreciate any guidance.
Get all Savithri TV Serial Updates, Playtime Schedule, New Episodes & Show Timings. Check Savithri Latest news, Photos, Videos and more! Jun 24, 2016 - They shared a picture on social media, captioned, 'Cast of Savithri having fun on the sets!! Watch Savithri at 7 PM only on ETV telugu.' Savitri telugu serial cast. Savitri (2016) cast and crew credits, including actors, actresses, directors, writers and more.
EDIT: I have updated the code with some suggestions from users, still seeing quick divergence. The guesses in there are way too high. If I figure this out I will update it to working.
Sample Fortran Computer Programs This page contains a list of sample Fortran computer programs associated with our textbook. In the following table, each line/entry contains the program name, the page number where it can be found in the textbook, and a brief description.
2 Answers
It seems that the initial values for xold
and xolder
are too far from the solution. If we change them as
and changing the threshold for convergence more tightly as
then we get
Here, we note that the function f(x)
is defined as
where terms in Lines (1) and (3) are both constant, while terms in Line (2) are some constants over D
. So, we see that f(D) = c1 - 2.0 * log( D / c2 )
, so we can obtain the solution analytically as D = c2 * exp(c1/2.0) = 7.26526809959e-5
, which agrees well with the numerical solution above. To get a rough idea of where the solution is, it is useful to plot f(D)
as a function of D
, e.g. using Gnuplot.
But I am afraid that the expression for f(D)
itself (given in the Fortran code) might include some typo due to many parentheses. To avoid such issues, it is always useful to first arrange the expression for f(D)
as simplest as possible before making a program.(One TIP is to extract constant factors outside and pre-calculate them.)
Also, for debugging purposes it is sometimes useful to check the consistency of physical dimensions and physical units of various terms. Indeed, if the magnitude of the obtained solution is too large or too small, there might be some problem of conversion factors for physical units, for example.
You very clearly declare the function in the interface (and the implementation) as
So you need to pass 7 arguments to it. And none of them are optional.
But when you call it, you call it as
supplying a single argument to it. When you try to compile it with gfortran
for example, the compiler will complain for not getting any argument for D
(the second dummy argument), because it stops with the first error.
Not the answer you're looking for? Browse other questions tagged fortrannumerical-methodsfluid-dynamics or ask your own question.
Jump to navigationJump to searchIn numerical analysis, the secant method is a root-finding algorithm that uses a succession of roots of secant lines to better approximate a root of a functionf. The secant method can be thought of as a finite-difference approximation of Newton's method. However, the method was developed independently of Newton's method and predates it by over 3000 years.[1]
The method[edit]
The secant method is defined by the recurrence relation
As can be seen from the recurrence relation, the secant method requires two initial values, x0 and x1, which should ideally be chosen to lie close to the root.
Derivation of the method[edit]
Starting with initial values x0 and x1, we construct a line through the points (x0, f(x0)) and (x1, f(x1)), as shown in the picture above. In slope–intercept form, the equation of this line is
The root of this linear function, that is the value of x such that y = 0 is
We then use this new value of x as x2 and repeat the process, using x1 and x2 instead of x0 and x1. We continue this process, solving for x3, x4, etc., until we reach a sufficiently high level of precision (a sufficiently small difference between xn and xn−1):
Convergence[edit]
The iterates of the secant method converge to a root of , if the initial values and are sufficiently close to the root. The order of convergence is φ, where
is the golden ratio. In particular, the convergence is superlinear, but not quite quadratic.
This result only holds under some technical conditions, namely that be twice continuously differentiable and the root in question be simple (i.e., with multiplicity 1).
If the initial values are not close enough to the root, then there is no guarantee that the secant method converges. There is no general definition of 'close enough', but the criterion has to do with how 'wiggly' the function is on the interval . For example, if is differentiable on that interval and there is a point where on the interval, then the algorithm may not converge.
Comparison with other root-finding methods[edit]
The secant method does not require that the root remain bracketed, like the bisection method does, and hence it does not always converge. The false position method (or regula falsi) uses the same formula as the secant method. However, it does not apply the formula on and , like the secant method, but on and on the last iterate such that and have a different sign. This means that the false position method always converges.
The recurrence formula of the secant method can be derived from the formula for Newton's method
by using the finite-difference approximation
Secant Method Pdf
The secant method can be interpreted as a method in which the derivative is replaced by an approximation and is thus a quasi-Newton method.
If we compare Newton's method with the secant method, we see that Newton's method converges faster (order 2 against φ ≈ 1.6). However, Newton's method requires the evaluation of both and its derivative at every step, while the secant method only requires the evaluation of . Therefore, the secant method may occasionally be faster in practice. For instance, if we assume that evaluating takes as much time as evaluating its derivative and we neglect all other costs, we can do two steps of the secant method (decreasing the logarithm of the error by a factor φ2 ≈ 2.6) for the same cost as one step of Newton's method (decreasing the logarithm of the error by a factor 2), so the secant method is faster. If, however, we consider parallel processing for the evaluation of the derivative, Newton's method proves its worth, being faster in time, though still spending more steps.
Generalizations[edit]
Broyden's method is a generalization of the secant method to more than one dimension.
The following graph shows the function f in red and the last secant line in bold blue. In the graph, the x intercept of the secant line seems to be a good approximation of the root of f.
A computational example[edit]
The secant method is applied to find a root of the function f(x) = x2 − 612. Here is an implementation in the MATLAB language (from calculation, we expect that the iteration converges at x = 24.7386):
Notes[edit]
- ^Papakonstantinou, J., The Historical Development of the Secant Method in 1-D, retrieved 2011-06-29
See also[edit]
References[edit]
- Kaw, Autar; Kalu, Egwu (2008), Numerical Methods with Applications (1st ed.).
- Allen, Myron B.; Isaacson, Eli L. (1998). Numerical analysis for applied science. John Wiley & Sons. pp. 188–195. ISBN978-0-471-55266-6.
External links[edit]
- Secant Method Notes, PPT, Mathcad, Maple, Mathematica, Matlab at Holistic Numerical Methods Institute
- Weisstein, Eric W.'Secant Method'. MathWorld.