0% found this document useful (0 votes)
47 views4 pages

Name-Akshay Bora ROLL NO. - 7682 QUESTION 2. Root of A Transcendental Equation Using Bisection Method Program

The document describes a C++ program that uses the bisection method to find the root of a transcendental equation in a given interval. The program takes initial guesses for the endpoints of the interval, calculates the midpoint at each iteration, and narrows in on the root within a specified tolerance. It outputs the iterations, showing how the interval is bisected and converges on the root of approximately 3.4256.

Uploaded by

Akshay Bora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views4 pages

Name-Akshay Bora ROLL NO. - 7682 QUESTION 2. Root of A Transcendental Equation Using Bisection Method Program

The document describes a C++ program that uses the bisection method to find the root of a transcendental equation in a given interval. The program takes initial guesses for the endpoints of the interval, calculates the midpoint at each iteration, and narrows in on the root within a specified tolerance. It outputs the iterations, showing how the interval is bisected and converges on the root of approximately 3.4256.

Uploaded by

Akshay Bora
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

NAME-AKSHAY BORA

ROLL NO. -7682


QUESTION 2. Root of a Transcendental Equation using Bisection
method

 PROGRAM:
#include <iostream>
#include<stdlib.h>
#include<math.h>
#include<iomanip>
#define f(x)(x*tan(x)-1) /*Defining the function whose roots are to be found*/
using namespace std;
int main()
{
double a, b,tol;
double c = a;
int n=1;
cout<<"This Program Prints the root of a Transcendental Equation in a given
interval using Bisection method"<<endl;
s:cout<<"\nEnter initial guesses :\n\t";cout<<"a :";cin>>a;cout<<"\tb :";cin>>b;
if (f(a)==0)
{
cout<<"The root of the equation is: "<<a<<endl;
goto ab;}
if (f(b)==0){
cout<<"The root of the equation is: "<<b<<endl;
goto ab;}
if (f(a) * f(b) >= 0)
{
cout << "\t\t Wrong Intervals chosen. Please give the Range again.\n";
goto s;
}
cout<<"Enter tolerance value : ";
cin>>tol;

cout<<"Sl.no."<<setw(6)<<"a"<<setw(15)<<"f(a)"<<setw(15)<<"b"<<setw(15)<<"f(
b)"<<setw(15)<<"c"<<setw(15)<<"f(c)"<<endl;/*gives a proper heading*/

cout<<"____________________________________________________________
__________________________"<<endl;
/*The following would do the bisection procedure and then print the required
data and finallly finds out the root upto the required accuracy*/
do
{
c = (a+b)/2;

cout<<n<<setw(10)<<a<<setw(15)<<f(a)<<setw(15)<<b<<setw(15)<<f(b)<<setw(1
5)<<c<<setw(15)<<f(c)<<endl;
if (f(c) == 0.0)
break;
else if (f(c)*f(a) < 0)
b = c;
else
a = c;
n++;
}
while (fabs(b-a) >= tol);
cout << "The value of root is : " << c;
ab:
return 0;
}

OUTPUT:
This Program Prints the root of a Transcendental Equation in a given interval using Bisection
method

Enter initial guesses :


a :3
b :5
Wrong Intervals chosen. Please give the Range again.

Enter initial guesses :


a :3
b :4
Enter tolerance value : 0.0001
Sl.no. a f(a) b f(b) c f(c)
___________________________________________________________________________
___________
1 3 -1.42764 4 3.63129 3.5 0.31105
2 3 -1.42764 3.5 0.31105 3.25 -0.646289
3 3.25 -0.646289 3.5 0.31105 3.375 -0.197626
4 3.375 -0.197626 3.5 0.31105 3.4375 0.0479481
5 3.375 -0.197626 3.4375 0.0479481 3.40625 -0.0768562
6 3.40625 -0.0768562 3.4375 0.0479481 3.42188 -0.0149789
7 3.42188 -0.0149789 3.4375 0.0479481 3.42969 0.0163507
8 3.42188 -0.0149789 3.42969 0.0163507 3.42578 0.000652759
9 3.42188 -0.0149789 3.42578 0.000652759 3.42383 -0.00717132
10 3.42383 -0.00717132 3.42578 0.000652759 3.4248 -0.00326135
11 3.4248 -0.00326135 3.42578 0.000652759 3.42529 -0.00130481
12 3.42529 -0.00130481 3.42578 0.000652759 3.42554 -0.000326155
13 3.42554 -0.000326155 3.42578 0.000652759 3.42566 0.000163269
14 3.42554 -0.000326155 3.42566 0.000163269 3.4256 -8.1451e-005
The value of root is : 3.4256
--------------------------------
Process exited after 29.83 seconds with return value 0
Press any key to continue . . .

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy