Numerical method for calculations of odd roots or to find zeroes of function
#include <iostream.h>
#include <math.h>
#include <iomanip.h>
double f(double x){
return tan(ALFA)-ALFA-Y;}
// ALFA is an angle that we are calculating and Y is free article seen (calculated) on right side of equation
main(){
double xl, xd, es,xn;
int maxit;
cout << " Podaj levi priblizek : ";
cin >>xl;
cout << " Podaj desni priblizek : ";
cin >>xd;
if(f(xl)*f(xd)>0){
cout <<" meje niso prave...";
return 1;}
cout <<" Podaj dopustno relativno napako : ";
cin >>es;
cout <<" Podaj maksimalno stevilo iteracij : ";
cin >>maxit;
double ea=1.1*es;
cout <<setw(6)<<"xl"<<setw(14)<<"xn"<<setw(14)<<"f(xn)" <<endl;
cout.flags(cout.left);
double xs=xd;
for( int i=0;i<=maxit;i++){
xn=xd-f(xd)*(xl-xd)/(f(xl)-f(xd));
ea=fabs((xn-xs)/xn);
if(ea<es)break ;
xs=xn;
cout <<setw(14) <<setprecision(8) <
<<setw(14) <<xn <<setw(14)<<f(xn) <<endl;
double test=f(xl)*f(xn);
if(test==0)return 0;
test>0 ? xl=xn : xd=xn;
//else if(test>0)
// xl=xn;
//else
// xd=xn;
}
cout <<" koren = " <<xn <<endl;
cout <<" ocena napake= " <<ea <<endl;
cout <<" stevilo iteracij= " <<i <endl;
if(i
cout <<" pravilni rezultat " <<endl;
return 0;}
cout <<" napacni rezultat ";
return 0;
}