Advertisement
Magentax

Regresie Exp

Jan 19th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. // Regresia exponentiala
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <conio.h>
  6. #include <math.h>
  7. #define NRMAX 10
  8.  
  9. void regexp (int m, float x[NRMAX], float y[NRMAX], float *a, float *b);
  10.  
  11. int main (void)
  12. {
  13.     int i,m;
  14.     float a,b;
  15.     float X[NRMAX],Y[NRMAX];
  16.  
  17.     printf("\nRegresia exponentiala \n");
  18.     printf("\nIntroduceti numarul experientelor:");
  19.     scanf("%d",&m);
  20.     printf("\nIntroduceti abscisele si ordonatele functiei:");
  21.     for (i=0;i<m;i++)
  22.         {
  23.             printf("\nX[%d]=",i);
  24.             scanf("%f",&X[i]);
  25.             printf("Y[%d]=",i);
  26.             scanf("%f",&Y[i]);
  27.         }
  28.  
  29.     regexp(m,X,Y,&a,&b);
  30.     printf("Rezultatul regresiei geometrice este: a=%f; b=%f",a,b);
  31.  
  32.     getch();
  33.     return 1;
  34. }
  35.  
  36. void regexp (int m, float x[NRMAX], float y[NRMAX], float *a, float *b)
  37. {
  38.     float sx,sy,sxx,sxy;
  39.     int i;
  40.  
  41.     sx=0;   sy=0;   sxx=0;  sxy=0;
  42.     for (i=0;i<m;i++)
  43.         {   sx=sx+(x[i]);
  44.             sy=sy+log(y[i]);
  45.             sxy=sxy+x[i]*log(y[i]);
  46.             sxx=sxx+x[i]*x[i];
  47.         }
  48.     *a=exp( (sy*sxx-sx*sxy)/(m*sxx-sx*sx) );
  49.     *b=exp( (m*sxy-sx*sy)/(m*sxx-sx*sx) );
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement