You are working on newton 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

   Newton-Raphson method

	
	

Newton-Raphson method

1. The method: The Newton-Raphson method is, such as bisection or secant methods, a technique for solving equations numerically. It is based on the linear approximation idea. Let f(x) the function for which we are going to find a zero, that is the root of the equation f(x) = 0. Let's assume that the zero of a function f(x) is near the point (x0, f(x0). The Taylor expansion for a function f(x) about the point (x0, y0) can be written as: f(x) = f(x0) + f'(x0)(x- x0) + (1/2!) f"(x0) (x - x0)2 + ... Let's stay in the first order, then: f(x) = f(x0) + f'(x0)(x - x0) The ratio f'(x0) = [f(x) - f(x0)]/(x - x0) is the tangent at the curve of the function at the point (x0,y0). It is also equal to the slope of the tangent line at this point(x0, f(x0)). Let's write the equation of this line like: t)x) = f'(x0) x + b (b is the y-intercept of the equation of the tangent). This line crosses the x-axis at the point x1, then: t(x) = f'(x0) x1 + b = 0. Therefore: b = - f'(x0) x1. Thus: t(x) = f'(x0) x + b = f'(x0) x - f'(x0) x1. We have then: At x = x0, t(x0) = f(x0); therefore: f(x0) = f'(x0)( x0 - x1); so x1 = x0 - f(x0)/f'(x0) Similarly, if we continue the iterative process until xn+1, we will get the nth estimate of the solution: xn+1 = xn - f(xn/f'(xn)     (1) We take then xn as a solution when the following condition is satisfied: (xn+1 - xn)/xn) <= E/100.0    2) Let's consider xn is the root r of the f(x) = 0, then: xn+1 = xn - f(xn)/f'(xn), thus: xn = xn. The relationship (2) is satisfied to the maximum. The more the first member of the inequality (2) is small, the more one gets near to the root of the function. This method requires: 1. Guessing a good estimate of x0, the nearest root of f(x) = 0, 2. knowing the derivative of the function f(x). 2. Example in clanguage // Program: newton-free-fall.c #include #include #include double g = 9.81; float y = 500; // The function //-------------- float f(float t) { return y - (g/2)*t*t; } // The derivative of the function //------------------------------ float f_der (float t) { return g*t; } float newton (float f(float To)){ float ss = 0; float c[41]; c[0] = 10.00 ; float E = 0.05; int i,n = 40; for(i=1;i<=n;i++) { c[i] = c[i-1] - f(c[i-1])/f_der(c[i-1]); if (abs((c[i] - c[i-1])/c[i-1]) <= E/100.0 ) { printf("nThe solution is T = %1.2f seconds.n", c[i]); ss= c[i]; i = n+1; } } return ss; } // --------The function main ------ int main() { newton(&f); return 0; } ------------- The execution gives: >newton_free_fall The solution is T = 9.90 seconds. >Exit code: 0


Custom Search


© 2007. The scientificsentence . All rights reserved.