Friday, May 31, 2013

Implementation of Iterative Method


In computational mathematics, an iterative method is a mathematical procedure that generates a sequence of improving approximate solutions for a class of problems. A specific implementation of an iterative method, including the termination criteria, is an algorithm of the iterative method. An iterative method is called convergent if the corresponding sequence converges for given initial approximations. A mathematically rigorous convergence analysis of an iterative method is usually performed; however, heuristic-based iterative methods are also common.
In the problems of finding the root of an equation (or a solution of a system of equations), an iterative method uses an initial guess to generate successive approximations to a solution. In contrast, direct methods attempt to solve the problem by a finite sequence of operations. In the absence of rounding errors, direct methods would deliver an exact solution (like solving a linear system of equations Ax = b by Gaussian elimination). Iterative methods are often the only choice for nonlinear equations. However, iterative methods are often useful even for linear problems involving a large number of variables (sometimes of the order of millions), where direct methods would be prohibitively expensive (and in some cases impossible) even with the best available computing power.

C code to find a real root of the equation 2x=cosx+3 using Iterative method:

  /***********************************************************
* You can use all the programs on  www.engineercse.blogspot.com
* for personal and learning purposes.
* contact azam.ruet10@gmail.com
* To find more C programs, do visit www.engineercse.blogspot.com
* and browse!
*
*                            Coding is poetry!!!

***********************************************************/
#include
#include
#include
#include

int main(){
    int i;
    float f,a,b,x,t;
    scanf("%f",&x);
    //x=(a+b)/2;
    if((sin(x)/2)<1 br="">        for(i=0;i<2000 br="" i="">            t=f;
            //x=0;
            //f=0;
            f=(cos(x)+3)/2;
            printf("%f\n",x);
            //t=f;

            x=f;
            if(fabs(f-t)<=0.0001)
                break;
            //t=f;
        }
        printf("\nThe Root is: %f",x);
    }
    else
        printf("\nThe Method cannot be applied..");

    getch();
}


sample output: 90

90.000000
1.275963
1.645290
1.462788
1.553900
1.508448
1.531154
1.519816
1.525479
1.522651
1.524063
1.523358
1.523710
1.523534

The Root is: 1.523622

No comments:

Post a Comment