Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///MAIN.CPP///
- ///ATTENTION ROOTFINDER.CPP MODIF POUR FCT 2 VARIABLES !!
- #include <iostream>
- #include "extremumFinder.h"
- #include "rootFinder.h"
- #include <cmath>
- #include <fstream>
- using namespace std;
- double f(double x,double y)
- {
- double a = 0.54533;
- return pow(pow(x,2)+pow(y+a,2)-1,3)-pow(x,2)*pow(y+a,3);
- }
- int main()
- {
- ofstream retour1 ("roots1.txt",ios::app);
- ofstream retour2 ("roots2.txt",ios::app);
- if (retour1)
- {
- for (double x=-1.139;x<1.139;x=x+0.004556)
- retour1 << x << ";" << getRoot_bmethod(f,x,-2, 0, pow(10,-3))<< endl;
- cout << "Fichier roots1.txt cree" << endl;
- }
- else
- cout << "ERREUR FICHIER";
- if (retour2)
- {
- for (double x=-1.139;x<1.139;x=x+0.004556)
- retour2 << x << ";" << getRoot_bmethod(f,x,0, 1, pow(10,-3))<< endl;
- cout << "Fichier roots2.txt cree" << endl;
- }
- else
- cout << "ERREUR FICHIER";
- }
- ///ROOTFINDER.CPP///
- #include <iostream>
- #include "rootFinder.h"
- #include <cmath>
- using namespace std;
- double getRoot_bmethod(double (*f)(double,double),double x, double a, double b, double eps)
- {
- double c=(b+a)/2;
- if(f(x,a)*f(x,b)>0) ///Si pas de zéro, renvoie "pas de zéro"
- return NAN;
- else if (fabs(f(x,a))<eps) ///Si a est le zéro
- return a;
- else if (fabs(f(x,b))<eps) ///Si b est le zéro
- return b;
- else if (fabs(f(x,c))<eps) ///Si c est direct le zéro
- return c;
- else ///Si au moins un zéro
- do
- {
- c=(b+a)/2;
- if (f(x,c)*f(x,b)>0)
- b=c;
- else
- a=c;
- }
- while (fabs(a-b)>eps);
- return c;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement