IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

 C Discussion :

comparaison des méthodes dichotomie, secante et Newton. "resolution des equations non lineare"


Sujet :

C

  1. #1
    Nouveau Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Décembre 2015
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 28
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Décembre 2015
    Messages : 9
    Points : 0
    Points
    0
    Par défaut comparaison des méthodes dichotomie, secante et Newton. "resolution des equations non lineare"
    bonjour tous le monde j'ai un probleme et j'esper que vous alle m'aider un peux :
    la question est :
    Faites la comparaison des méthodes dichotomie, secante et Newton. La convergence de Newton est tres rapide ici, dans le domaine une seule racine existe de plus la derivée est proche de 1. Evidemment nous n'avons pas toujours cette chance avec Newton.
    bon j'ai fait un essaie et j'ai pas trouve ma faute SVT AIDE MOI :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    #include <stdio.h> 
    #include <math.h> 
    float maFonc( float x) { 
    return 0.4*x*x*x - x*x + 0.7 ;
     }
     float deriv( float x)
    {
     return 1.2*x*x + 2*x ;
     }
     float newton ( float Fonc( float ), float Deriv(float ), float x0, float eps, float eps2, int MaxIter )
    {
     float d, y0, x1,y ;
     int nbIter=0; 
    y0=Fonc(x0); 
    d=Deriv(x0);
     while( fabs(y0) > eps && nbIter < MaxIter )
    {
     if (fabs(d)<eps2)
    {
     printf("\n derive proche de zero: %10.7f \n" , d );
     exit (-1); 
    } 
    if (y==0) return x1;
     x1 -= y0/d;
     y0= Fonc(x1); 
    d=Deriv(x1);
     nbIter++; 
    } return 1; 
    }
     float dichotomie( float Fonc( float ), float a, float b, float eps, int MaxIter )
    {
     float x, y;
     int nbIter=0; 
    x=(a+b)/2;
     y=Fonc(x); 
    while( fabs(y) > eps && nbIter < MaxIter )
    {
     if (y==0) return x;
     if (y * Fonc(a)< 0) b= x; 
    else a=x; x=(a+b)/2;
     y=Fonc(x); nbIter++;
     } 
    return x; 
    }

  2. #2
    Expert éminent
    Homme Profil pro
    Ingénieur développement matériel électronique
    Inscrit en
    Décembre 2015
    Messages
    1 564
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 60
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur développement matériel électronique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Décembre 2015
    Messages : 1 564
    Points : 7 640
    Points
    7 640
    Par défaut
    Bonjour,

    La fonction deriv est fausse!

    fonction newton, les variables y et x1 ne sont pas initialisées (en réalité x0 et x1 sont idem, et y et y0 aussi!)
    à la fin de newton faire return x; au lieu de return 1

    Cela devrait fonctionner

  3. #3
    Nouveau Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Décembre 2015
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 28
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Décembre 2015
    Messages : 9
    Points : 0
    Points
    0
    Par défaut MERCI Mr POUR ta reponce
    et Mr comme ca la fonction deriv et juste ou nn!!!
    et Mr que veut dire idem?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    63
    64
    65
    66
    67
    68
    69
     #include <stdio.h>
     #include <math.h>
     float maFonc( float x)
     float deriv( float x)
     
    {
     return 0.4*x*x*x - x*x + 0.7 ;
    }
     float newton ( float Fonc( float ), float Deriv(float ), float x0, float eps, float eps2, int MaxIter ){
     float d, y0, x1 ; int nbIter=0;
    y0=Fonc(x0); d=Deriv(x0);
     
     while( fabs(y0) > eps && nbIter < MaxIter ){
     if (fabs(d)<eps2){
    printf("\n derive proche de zero: %10.7f \n" , d );
     exit (-1);
     }
    if (y==0) return x1;
    x1 -= y0/d;
    y0= Fonc(x1);
    d=Deriv(x1);
    ndIter++;
    }
     return x;
     }
     float dichotomie( float Fonc( float ), float a, float b, float eps, int MaxIter ){
     float x, y; int nbIter=0;
     x=(a+b)/2; y=Fonc(x);
     while( fabs(y) > eps && nbIter < MaxIter ){
     if (y==0) return x;
     if (y * Fonc(a)< 0) b= x;
     else a=x;
     x=(a+b)/2; y=Fonc(x);
     nbIter++;
     }
     return x;
     }
     float secante(float Fonc(float ), float x0, float g, float eps, int MaxIter ){
     float tmp, y0,y1, x1=g; int nbIter=0;
     y0=Fonc(x0); y1=Fonc(x1);
     while (fabs(y1-y0) > eps && nbIter < MaxIter ){
    tmp=x1;
     x1 -= y1 *(x1-x0) / (y1-y0);
     x0=tmp; y0=Fonc(x0);
     y1 = Fonc(x1);
     if (y1 == 0) return x1;
     nbIter++;
     }
     return x1;
     }
     int main(){
     int i; float x, g, d, psi, x_init, xd, xs, xn, psi2;
     printf("\n\t\tComparaison des methodes \n");
     printf("\nIntervalle et Precision : ");
     scanf("%f%f%f", &g, &d,&psi);
     if (maFonc(g)* maFonc(d) >0) {
     printf("\nEquation n'a peut etre pas de solution\n"); return -1;
     }
     x_init=(g+d)/2;
     printf("Nbre Iter Dichotomie Secante newton");
     for ( i=2; i < 15; i++){
     xd=dichotomie(maFonc,g,d,psi, i);
     xs=secante(maFonc,x_init,d,psi, i);
     xn=newton(maFonc, deriv , x_init, psi,  psi2, i); 
     
     printf("\n %7d %10.7f %10.7f" , i, xd , xs ,xn);
     }
     putchar('\n'); return 0;
     }

  4. #4
    Expert éminent
    Homme Profil pro
    Ingénieur développement matériel électronique
    Inscrit en
    Décembre 2015
    Messages
    1 564
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 60
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur développement matériel électronique
    Secteur : High Tech - Électronique et micro-électronique

    Informations forums :
    Inscription : Décembre 2015
    Messages : 1 564
    Points : 7 640
    Points
    7 640
    Par défaut
    Bonjour,

    Oui pour la dérivée

    Idem veut dire que sont des variables identiques, donc la fonction devient :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    float newton( float Fonc(float) , float Deriv(float) , float x , float eps , float eps2 , int MaxIter ) {
    	int nbIter = 0;
    	float y = Fonc( x );
    	float d = Deriv( x );
     
    	while ( fabs( y ) > eps  &&  nbIter < MaxIter ) {
    		if ( fabs( d ) < eps2 ) {
    			printf("\n derive trop proche de zero: %10.7f \n" , d );
    			exit( -1 );
    		}
    		x -= y / d;
    		y = Fonc( x );
    		d = Deriv( x );
    		nbIter++;
    	}
    	return x;
    }

Discussions similaires

  1. [Info] génération des méthodes parentes
    Par Popeye75 dans le forum Eclipse Java
    Réponses: 2
    Dernier message: 08/12/2005, 17h24
  2. JAVA - Passer des Objects à des méthodes
    Par canou94 dans le forum CORBA
    Réponses: 2
    Dernier message: 15/11/2005, 22h39
  3. Réponses: 5
    Dernier message: 30/05/2005, 16h58
  4. Editeur de texte - liste des méthodes
    Par Carlito_superheros dans le forum Langages de programmation
    Réponses: 3
    Dernier message: 30/03/2005, 12h52
  5. [Info]descriptif des méthode ?
    Par java_math dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 01/06/2004, 08h36

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo