tampurus

Unit 2.5 Exponential curve

Jun 10th, 2022 (edited)
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<math.h>
  4. int main()
  5. {
  6.  
  7. int n,i;
  8. float Y[20],sumx=0,sumy=0,sumxy=0,sumx2=0,x[20],y[20];
  9. float a,b,A;
  10. printf("\n C program for Exponential Curve fitting\n");
  11. printf("\n Enter the value of number of terms n:");
  12. scanf("%d",&n);
  13. printf("\n Enter the values of x:");
  14. for(i=0;i<=n-1;i++)
  15. {
  16. scanf("%f",&x[i]);
  17.  
  18. }
  19. printf("\n Enter the values of y:");
  20. for(i=0;i<=n-1;i++)
  21. {
  22. scanf("%f",&y[i]);
  23. }
  24. for(i=0;i<=n-1;i++)
  25. {
  26. Y[i]=log(y[i]);
  27. }
  28. for(i=0;i<=n-1;i++)
  29. {
  30. sumx=sumx +x[i];
  31. sumx2=sumx2 +x[i]*x[i];
  32. sumy=sumy +Y[i];
  33. sumxy=sumxy +x[i]*Y[i];
  34.  
  35. }
  36. A=((sumx2*sumy -sumx*sumxy)*1.0/(n*sumx2-sumx*sumx)*1.0);
  37. b=((n*sumxy-sumx*sumy)*1.0/(n*sumx2-sumx*sumx)*1.0);
  38. a=exp(A);
  39. printf("\n\n The curve is Y= %4.3fe^%4.3fX",a,b);
  40. return(0);
  41. }
  42.  
  43.  
  44. // output
  45. C program for Exponential Curve fitting
  46.  
  47. Enter the value of number of terms n:4
  48.  
  49. Enter the values of x:4
  50. 8
  51. 12
  52. 16
  53.  
  54. Enter the values of y:6
  55. 9
  56. 12
  57. 17
  58.  
  59.  
  60. The curve is Y= 4.366e^0.085X
Add Comment
Please, Sign In to add comment