0% found this document useful (0 votes)
306 views

Bisection Method Algorithm

1. The document lists the names of 6 students who submitted an assignment to Md. Mehedi Hasan. 2. It then provides descriptions and algorithms for the bisection method, fixed-point iteration method, and Newton-Raphson method for finding roots of equations. 3. C programming code is provided for each of the numerical methods to demonstrate their implementation.

Uploaded by

Syed Tuhin
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
306 views

Bisection Method Algorithm

1. The document lists the names of 6 students who submitted an assignment to Md. Mehedi Hasan. 2. It then provides descriptions and algorithms for the bisection method, fixed-point iteration method, and Newton-Raphson method for finding roots of equations. 3. C programming code is provided for each of the numerical methods to demonstrate their implementation.

Uploaded by

Syed Tuhin
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Assignment

Submitted by:
1. Imran Hossain_162-15-7672
2. Sk Hasibul Islam_162-15-7748
3. Fazlur Rahman_162-15-7796
4. Nasir Uddin_162-15-7797
5. Asif Ahmed Nibir_162-15-7862
6. Zayan Tipu_162-15-7758

Submitted to: Md. Mehedi Hasan


Bisection method

The bisection method in mathematics is a root-finding


method that repeatedly bisectsan interval and then selects
a subinterval in which a root must lie for further
processing. It is a very simple and robust method, but it is
also relatively slow. Because of this, it is often used to
obtain a rough approximation to a solution which is then
used as a starting point for more rapidly converging
methods. The method is also called the interval
halving method,] the binary search method, or
the dichotomy method.
Bisection Method Algorithm:
Start

1. Decide initial values for x1 and x2 and stopping criterion, E.


2. Compute f1 = f(x1) and f2 = f(x2).
3. If f1 * f2>0, x1 and x2 do not bracket any root and go to step 7;
Otherwise continue.
4. Compute x0 = (x1+x2)/2 and compute f0 = f(x0)
5. If f1*f0 < 0 then
set x2 = x0
else
set x1 = x0
set f1 = f0
6. If absolute value of (x2 – x1)/x2 is less than error E, then
root = (x1 + x2)/2
write the value of root
go to step 7
else
go to step 4
7. Stop.
Bisection Method C Programming:
#include<stdio.h>
#include<math.h>
float fun (float x)
{
return (x*x*x - 4*x - 9);
}
void bisection (float *x, float a, float b, int *itr)
{
*x=(a+b)/2;
++(*itr);
printf("Iteration no. %3d X = %7.5f\n", *itr, *x);
}
void main ()
{
int itr = 0, maxmitr;
float x, a, b, allerr, x1;
printf("\nEnter the values of a, b, allowed error and maximum
iterations:\n");
scanf("%f %f %f %d", &a, &b, &allerr, &maxmitr);
bisection (&x, a, b, &itr);
do
{
if (fun(a)*fun(x) < 0)
b=x;
else
a=x;
bisection (&x1, a, b, &itr);
if (fabs(x1-x) < allerr)
{
printf("After %d iterations, root = %6.4f\n", itr, x1);
return 0;
}
x=x1;
}
while (itr < maxmitr);
printf("The solution does not converge or iterations are not
sufficient");
return 1;
}

Fixed-point iteration
Fixed-point iteration algorithm
Start

Fixed-point iteration Method C


Programming:
#include <stdio.h>
#include <math.h>

double f(double x)
{
return x*x*x*x-3*x*x-3;
}

double g(double x)
{
return pow(3*x*x+3,.25);
}

int main()
{
double p, p0, Tol;
int i=1;
int No;

printf("Enter approximate p: ");


scanf ("%lf", &p0);

printf("Desired Tolerance: ");


scanf ("%lf", &Tol);

printf("Maximum Iterations: ");


scanf ("%d", &No);

while (i<=No)
{
p = g(p0);

if((fabs(p-p0))<Tol)
{
break;
}
printf("Iteration %d: Current value = %lf\n", i, p);

i++;
p0=p;

if (i>No)
{
printf("Method Failed after %d", No);
printf(" iterations");
}

Newton–Raphson Method:
The Newton-Raphson method uses the tangent of a curve to iteratively approximate a
zero of a function, f(x). The Modified Newton-Raphson method uses the fact
that f(x) and u(x) := f(x)/f'(x) have the same zeros and instead approximates a zero
of u(x).
Newton–Raphson Method algorithm:

Newton–Raphson Method C
Programming:
#include<stdio.h>
#include<math.h>
float f(float x)
{
return x*log10(x) - 1.2;
}
float df (float x)
{
return log10(x) + 0.43429;
}
void main()
{
int itr, maxmitr;
float h, x0, x1, allerr;
printf("\nEnter x0, allowed error and maximum iterations\n");
scanf("%f %f %d", &x0, &allerr, &maxmitr);
for (itr=1; itr<=maxmitr; itr++)
{
h=f(x0)/df(x0);
x1=x0-h;
printf(" At Iteration no. %3d, x = %9.6f\n", itr, x1);
if (fabs(h) < allerr)
{
printf("After %3d iterations, root = %8.6f\n", itr, x1);
return 0;
}
x0=x1;
}
printf(" The required solution does not converge or iterations are
insufficient\n");
return 1;
}

You might also like