Magentax

Regresie Hip

Jan 19th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 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 reghip (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+x[i];
  15.             sy=sy+1/y[i];
  16.             sxy=sxy+x[i]/y[i];
  17.             sxx=sxx+x[i]*x[i];
  18.         }
  19.         *a=(m*sxy-sx*sy)/(m*sxx-sx*sx);
  20.         *b=(sxx*sy-sx*sxy)/(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 HIPERBOLICA");
  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.     reghip(m,X,Y,&a,&b);
  42.     printf("Rezultatul regresiei hiperbolice este: a=%f; b=%f",a,b);
  43.  
  44.     getch();
  45.     return 1;
  46. }
Add Comment
Please, Sign In to add comment