You are working on secant function
 
search
 


Contents:


swap function:
Swapping two values to change their addresses.
a

max function:

The largest number among two.
a

absolute value function:

The positive value of a number.
a

sorting function:

How to sort an array.
a

bisection function:

Bissection method used to solve equations by computing, example of cable strung ..
a

Newton-Raphson function:

To solve equations numerically, example of free fall motion ..
a

Secant function:

To solve equations numerically, example of free fall motion ..
a

isPrime function:

This function tests whether an integer is prime..
a

abundant function:

This function tests whether an integer is abundant..
a

factorial function:

Factorial of an integer..
a

quadratic function:

solving a quadratic equation ..
a

even_odd function:

To know if an integer is even or odd ..
a

mean value function:

To calculate the arithmetic mean of some values..
a

reverse function:

To reverse an integer and to know whether a string is palindrome..
a

least squares function :

To calculate the slope and the y_intercept of a linear equation ..
a

Monte Carlo method:

To calculate integrales or probabilities using Monte Carlo technique ..
a

2 and 3 equations systems solving :

To solve the 2 and 3 equations systems with 2 and 3 variables ..
a

Interpolation and Extrapolation :

To solve for lacking values in graphs or tables ..
a

Integer divisors :

Gives the divisors fo an integer and tests whether it is prime ..
a

Amicable pair :

Gives, if it exists, the amicable number of a given integer ..
a

Perfect numbers :

Tests whether a positive integer is perfect, and more ..
a

Periodic table of elements:

Periodic table of elements in C language, and more ..
a

Playing TicTacToe

Using some Fortran90 language funtionalities, and more ..
a


a
home

   Secant method


	

Secant method

1. The method: This method requires guessing the two first values close to the root x0 and x1 for the solution of the equation f(x) = 0. The secant from the point (x0, f(x0)) to the point (x1, f(x1)) cross the x axis at the point (x2, 0)). From this x-intercept, we get the point (x2, f(x2)). The second iteration consists of drawing the secant from the point (x1, f(x1)) to the point (x2, f(x2)). The related x-intercept of this secant is x3. From this, we get the point (x3, f(x3)). The third iteration consists of drawing the secant from the point (x2, f(x2)) to the point (x3, f(x3)). The related x-intercept of this secant is x4, ... and so on until we get an x-intercept closer to the root of the function f(x); that is a sufficiently high level of precision corresponding to a small difference between xn and xn-1. The secant related to the segment 0 and x1, can be found as follow: y ax + b f(x0) = a x0 + b    (1) f(x1) = a x1 + b    (2) Subtracting (1) from (2), yields: f(x1) - f(x0) = a (x1 - x0), then: a = (f(x1) - f(x0))/(x1 - x0) Subtracting (1) from 2 x (2), yields: 2 f(x1) - f(x0) = a (2 x1 - x0) + b then: b = 2 f(x1) - f(x0) - a (2 x1 - x0) Substituting the expression of "a" yields: b = 2 f(x1) - f(x0) - (f(x1) - f(x0)) - x1 (f(x1) - f(x0))/(x1 - x0) = f(x1) - x1 (f(x1) - f(x0))/(x1 - x0) Then: y ax + b = x (f(x1) - f(x0))/(x1 - x0) + f(x1) - x1 (f(x1) - f(x0))/(x1 - x0) ) = = (x - x1) (f(x1) - f(x0))/(x1 - x0) + f(x1) For y = 0, we have x2: x2= - f(x1) (x1 - x0)/ (f(x1) - f(x0)) + x1 The next will have the following expression: x3= - f(x2) (x2 - x1)/ (f(x2) - f(x1)) + x2 ... The nth x-intercept is: xn= xn-1 - f(xn-1) (xn-1 - xn-2)/ (f(xn-1) - f(xn-2)) 2. Example in clanguage #include #include #include double g = 9.81; float y = 500, to, t1, z = 0.05; // First function -------- float f(float t) { return y - (g/2)*t*t; } typedef float (*PFUN) (float); float secant (PFUN f, float to, float t1){ float ss = 0; float c[21]; c[0] = to ; c[1] = t1 ; int i=1,n = 20; for (i =1; i<=n; i++){ c[i+1] = c[i] - (c[i] - c[i-1])*f(c[i])/(f(c[i]) - f(c[i-1])); printf("%f n", c[i+1]); if (abs((c[i] - c[i-1])/c[i-1]) <= z/100.0 ) { printf("nThe solution is t = %f seconds.n", c[i+1]); ss= c[i]; i = n+1; } } return ss; } // ---------------------The main ------------- int main() { printf("n Input values for t0 and t1 (in seconds) : --> "); scanf("%f%f", &to, &t1); secant (&f,to,t1); return 0; } The execution gives: ------------------- secant_free_fall 10 11 Input values for t0 and t1 (in seconds) : --> 10.092229 The solution is t = 10.092229 seconds. >Exit code: 0


Custom Search


© 2007. The scientificsentence . All rights reserved.