Magentax

Regresie Geo

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