Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- c// algo y = a * e ^(b*x)
- start
- Read number of data(n)
- for i=1 to n:
- 1. read xi and yi
- 2. Next I
- Initializ
- 1. sumx=0
- 2. sumx2 = 0
- 3. sumy = 0
- 4. sum xy =0
- calculate required sum
- for i =1 to n:
- 1. sumx= sumx + (xi)
- 2. sumx2 = sumx2 + (xi)*(xi)
- 3. sumy = sumy + log(yi)
- 4. sumxy =sumxy + (xi) * log(yi)
- Next i
- calculate required constant A and B of Y = A + Bx
- A = (sumx * sumy - n*sumxy)/(sumx*sumx - n*sumx2)
- B = (sumy - n*A)/sumx
- a = pow(10,A)
- b = B/log10(e)
- display the value of and b
- stop
- // program
- #include <stdio.h>
- #include<math.h>
- #define e 2.718
- int main()
- {
- int n;
- float a,x[10],y[10],sumx=0,sumy=0,sumx2=0,sumxy=0;
- printf("Enter the value of n\n");
- scanf("%d",&n);
- printf("Enter the value of x and y\n");
- for(int i=1 ; i<=n ; i++){
- scanf("%f",&x[i]);
- }
- for(int i=1 ; i<=n ; i++){
- scanf("%f",&y[i]);
- }
- for(int i=1 ; i<=n ; i++){
- sumx = sumx + x[i];
- sumx2 = sumx2 + ((x[i])*(x[i]));
- sumy = sumy + log(y[i]);
- sumxy = sumxy + ((x[i]) * log(y[i]));
- }
- float A = ((sumx * sumy) - (n*sumxy))/((sumx*sumx) - (n*sumx2));
- float B = (sumy - (n*A))/sumx;
- a = pow(10,A);
- float b = B/log10(e);
- printf("\n y= %.2fx + %.2f",a,b);
- return 0;
- }
- /*
- Output
- Enter the value of n
- 5
- Enter the value of x and y
- 1
- 5
- 7
- 9
- 12
- 10
- 15
- 12
- 15
- 21
- y= 1.15x + 0.88
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement