#include<iostream.h> #include<conio.h> #include<math.h> float f(float x) { float f=pow(x,3)-18; return(f); } void main() { clrscr(); cout<<"the given equation is x^3-18:"<<endl; float x1,x2,x0,c,xm,n; cout<<"enter the interval(a,b)"<<endl; cout<<"\n enter x1="; cin>>x1; cout<<"\n enter x2="; cin>>x2; cout<<"\n the value of f("<<x1<<"):"<<f(x1); cout<<"\n the value of f("<<x2<<"):"<<f(x2); cout<<"\n the value of f("<<x0<<"):"<<f(x0); if (f(x1)*f(x2)<0) {do {x0=(x1*f(x2)-x2*f(x1))/(f(x2)-f(x1)); c=f(x1)*f(x0); if(c<0) x1=x0; else if(c>0) x2=x0; n++; if(c==0) break; xm=(x1*f(x2)-x2*f(x1))/(f(x2)-f(x1)); } while(fabs(xm-x0)>=0.0001); cout<<"root of the given equation on given tolerance is"<<x0<<endl; cou...
Posts
#include<iostream.h> #include<conio.h> #include<math.h> float f(float x) { float f=pow(x,3)+x-1; return(f); } void main() { clrscr(); cout<<"the given equation is x^3+x-1:"<<endl; float x1,x2,x0,c,xm,n; cout<<"enter the interval(a,b)"<<endl; cout<<"\n enter x1="; cin>>x1; cout<<"\n enter x2="; cin>>x2; cout<<"\n the value of f("<<x1<<"):"<<f(x1); cout<<"\n the value of f("<<x2<<"):"<<f(x2); cout<<"\n the value of f("<<x0<<"):"<<f(x0); if (f(x1)*f(x2)<0) {do {x0=(x1*f(x2)-x2*f(x1))/(f(x2)-f(x1)); c=f(x1)*f(x0); x1=x2; x2=x0; n++; if(c==0) break; xm=(x1*f(x2)-x2*f(x1))/(f(x2)-f(x1)); } while(fabs(xm-x0)>=0.0001); cout<<"root of the given equation on given tolerance is"<<x0<<endl; cout<<"no. of iter...