Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <math.h>
- #define NRMAX 10
- void reggeo (int m, float x[NRMAX], float y[NRMAX], float *a, float *b)
- {
- float sx,sy,sxx,sxy;
- int i;
- sx=0; sy=0; sxx=0; sxy=0;
- for (i=0;i<m;i++)
- { sx=sx+log(x[i]);
- sy=sy+log(y[i]);
- sxy=sxy+log(x[i])*log(y[i]);
- sxx=sxx+log(x[i])*log(x[i]);
- }
- *a=exp((sy*sxx-sx*sxy)/(m*sxx-sx*sx));
- *b=(m*sxy-sx*sy)/(m*sxx-sx*sx);
- }
- int main (void)
- {
- int i,m;
- float a,b;
- float X[NRMAX],Y[NRMAX];
- printf("REGRESIA GEOMETRICA");
- printf("\nIntroduceti numarul experientelor:");
- scanf("%d",&m);
- printf("\nIntroduceti abscisele si ordonatele functiei:");
- for (i=0;i<m;i++)
- {
- printf("\nX[%d]=",i);
- scanf("%f",&X[i]);
- printf("Y[%d]=",i);
- scanf("%f",&Y[i]);
- }
- reggeo(m,X,Y,&a,&b);
- printf("Rezultatul regresiei geometrice este: a=%f; b=%f",a,b);
- getch();
- return 1;
- }
Add Comment
Please, Sign In to add comment