1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| #include <iostream>
#include <ctime>
#include <cstdlib>
#include <time.h>
using namespace std;
struct FctR { // Qui permet de manipuler les fonctions réelles
virtual double operator()(double) const = 0;
virtual double derivee(double) const = 0;
};
class AlgorithmeR { //Permet une implantation des algorithme numérique i.e : x(n+1)=g(n,x(n))
public:
AlgorithmeR(double valeur_init, FctR & f):x_n(valeur_init),n_iter(0),fct(f){};
AlgorithmeR & operator++(){
calcul_iter();
++n_iter;
return (*this);
}
private:
virtual void calcul_iter() = 0;
double x_n;
int n_iter;
FctR & fct;
};
class Cubique : public FctR { //Qui code les fonctions : f(x)=(a*x+b)^3
public:
Cubique(double a,double b):a(a),b(b){};
~Cubique(){};
double operator()(double x) const { return (a*x+b)* (a*x+b)* (a*x+b); };
double derivee(double x) const{return 3*a*(a*x+b)*(a*x+b);};
private:
double a,b;
};
class Newton : public AlgorithmeR {
public:
Newton(double x0,Cubique & c):debut(x0),cube(c){};
friend ostream& operator<<(ostream&,const Newton &);
Newton& operator++(int x){
double x_N;
Cubique F;
x_N=x-(F(x)/derivee(x));
}
private:
double debut;
Cubique & cube;
};
ostream& operator<<(ostream& out,const Newton &d ){
return out << d.cube <<endl;
}; |
Partager