Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

C Programming - II

Paper - 204
Unit- IV
By
Dr. Francis L
Assistant Professor
Department of Physics
GFGC – K R Pura
B’lore-36
C programming-II
• Program for (i) finding the roots using a) Newton-Raphson
method and b) Bisection method, (ii) solving a system of linear
equations (Gauss elimination method), (iii) Evaluating integrals
using Simpson’s and trapezoidal rules, (iv) solving ordinary
differential equations based on Euler and Runge-Kutta methods,
Fitting data using (i) Least square fitting (ii) Lagrange’s
interpolation.
C Program: Newton-Raphson Method
The Newton-Raphson Method, is a technique of finding a solution to an equation in
one variable f(x) = 0 with the means of numerical approximation. It finds the solution
by carrying out iterations. It starts with one initial guess for finding real root of non-
linear equations.
In Newton Raphson method if x0 is initial guess then next approximated root x1 is
obtained by following formula:

.
Algorithm for Newton Raphson Method:
An algorithm for Newton Raphson method involves repetition of above process i.e.
we use x1 to find x2 and so on until we find the root within desired accuracy.
C-program for finding the roots using Newton-Raphson method:
run the program with x0=2 as the first approximation, up to 5 iterations
Newton Raphson method for finding real root of nonlinear equation in C programming

Let the non-linear equation be 𝑓 𝑥 = 3𝑥 − 𝑐𝑜𝑠𝑥 − 1

In this C program, x0 is initial guess value, e is tolerable error and f(x) is non-linear
function whose root is being obtained using Newton method.
Output
Advantages:
• Newton –Raphson method is best to solve the non-linear equations. It can
also be used to solve the system of non-linear equations, non-linear
differential and non-linear integral equations. The order of convergence is
quadric i.e. of second order which makes this method fast as compared to
other methods. It is very easy to implement on computer.
• A graph of function against root(s) can be plotted to understand the
behavior of the given polynomial.
Exercise :
• Write a C-Program to find the roots of the given function 𝑓 𝑥 = 𝑥 − 𝑡𝑎𝑛𝑥
using Newton-Raphson’s method and plot the polynomial using a graph
sheet.

You might also like