Fortran Program For Secant Method Formula
- Posted in:
- 11/11/17
- 90

FORTRAN 77 Code. PROGRAM NEWTON. C NUMERICAL METHODS: FORTRAN Programs, (c)., Newton-Raphson and Secant Methods, Page 84. Formula xn+1 = xnāf(xn). For this reason, the secant method is often faster in. In most Fortran numerical analysis libraries.
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. 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. It seems that the initial values for xold and xolder are too far from the solution. If we change them as xold = 3.0d-5 xolder = 9.0d-5 and changing the threshold for convergence more tightly as IF (ABS(fx(xnew,L,Q,hf,rho,mu,rough)). Thank you for taking the time out of your day to help me.
I originally solved this problem in excel using solver and was given 0.799 inches, reasonable for the size of this system (according to my mentor). As far as the solution goes, I've tried cleaning up the parenthesis and ended up getting the same answers. Units have also been checked multiple times, and I am certain that those are right. I rewrote the function using my empirical derivation which took all factors besides D out of the function and got the same thing.
I didn't want to hard-wire the program and limit its usefulness. ā Dec 14 '15 at 4:44. @Jake Hmm, I see. And if you can calculate the answer by Excel, does it agree with the Fortran solution above (e.g. After some unit conversion etc)? At least, the secant code itself seems to be working correctly. [Also, by 'pre-calculate the constant factors', I mean using some temporary variables to store constant factors as a whole, e.g.
CoeffA = hf/(L* 4*Q/pi) to make it easy to see the structure of the expression (not hard-coding the literal numbers). This is also useful for the reader of this site, because it takes time to 'decode' the program. ā Dec 14 '15 at 5:25 1. Yes on excel the answer is reported in feet, so the number is multiplied by 12 to get to inches which ends up being ~0.799. I thought about doing coefficients but thought I couldn't because it would mess the function up but I am working on that now. I also realized I forgot a few terms from the colebrook equation which would explain a lot I am currently working with f=(1/SQRT(hf/((L/D)*(((4.0*Q)/(pi D 2))/2*g)))) & +2.0*log10((rough/(3.7*D))+ & ((2.51/((rho*(4.0*Q/piD2)*D/mu) & SQRT(hf/((L/D)*(((4.0*Q)/(piD**2))/2*g))))))) But am going to simplify it. Thanks for your help ā Dec 14 '15 at 5:30.
You very clearly declare the function in the interface (and the implementation) as FUNCTION f(L,D,Q,hf,rho,mu,rough) IMPLICIT NONE INTEGER,PARAMETER::DP=selected_real_kind(15) REAL(DP), PARAMETER::pi=3.14159265, g=9.81 REAL(DP), INTENT(IN)::L,Q,rough,rho,mu,hf,D REAL(DP)::fx END FUNCTION So you need to pass 7 arguments to it. And none of them are optional.
But when you call it, you call it as xnew=xold-fx(xold)*((xolder-xold)/(fx(xolder)-fx(xold)) 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.
Wolfram Web Resources The #1 tool for creating Demonstrations and anything technical. Explore anything with the first computational knowledge engine. Autocad 2010 32 Bit Product Key And Serial Number Free Download here. Explore thousands of free applications across science, mathematics, engineering, technology, business, art, finance, social sciences, and more.
Join the initiative for modernizing math education. Solve integrals with Wolfram Alpha. Walk through homework problems step-by-step from beginning to end. American Pageant 14th Edition Ch 25 Weather. Hints help you try the next step on your own.
Unlimited random practice problems and answers with built-in Step-by-step solutions. Practice online or make a printable study sheet. Collection of teaching and learning tools built by Wolfram education experts: dynamic textbook, lesson plans, widgets, interactive Demonstrations, and more. Knowledge-based programming for everyone.