BisectionMethod - cout<<"Enter values of a& b" cin>>a>>b cin.ignore float bisection:fn(float y float value=0 for(int

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/* Write a program to find the real root by bisection method for the equation   x^3  5x +1 = 0 */  #include<iostream>  #include<cmath>  using namespace std;  class bisection{       private:              float x[4];              float a,b,mid;              int i;       public:              void get_data(void );              float fn(float );              void set_data(void );  };  void bisection::get_data(void ){      for(i=3;i>=0;i--){         cout<<"Enter the coeff. of x^"<<i<<" : ";         cin>>x[i];         cin.ignore();      } 
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: cout<<"Enter values of a & b : "; cin>>a>>b; cin.ignore(); } float bisection::fn(float y){ float value=0; for(int m=0;m<4;m++){ value+=x[m]*pow(y,m); } return value; } void bisection::set_data(void ){ for(i=1;i<=10;i++){ mid=(a+b)/2; cout<<"For iteration no. "<<i<<", root = "<<mid<<'\n'; fn(mid)*fn(a)<0?b=mid:a=mid; } } int main(void ){ bisection root; root.get_data(); root.set_data(); return 0; }...
View Full Document

This note was uploaded on 04/02/2010 for the course ECE 403 taught by Professor K.k.singh during the Spring '10 term at Birla Institute of Technology & Science.

Page1 / 2

BisectionMethod - cout<<"Enter values of a& b" cin>>a>>b cin.ignore float bisection:fn(float y float value=0 for(int

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online