Advertisement
Guest User

polynomial gap thing

a guest
Oct 16th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main() //please take note, this is not the full version. i cannot understand the f_left/f_right parts
  5. { //so i just left it as is first. the upper parts should be all inside
  6. printf("Hello world!\n");
  7.  
  8. float stepsize; //should be the subinterval gap
  9. int p,q,r,s; //to replace a0,a1,a2,a3 because it is conflicitng with the end points
  10. float endpointax,endpointbx;
  11. float ay,by;
  12.  
  13. int k=0;
  14. float L,M;
  15.  
  16. int n;
  17.  
  18. printf("the cubic polynomial has the form of 'f(X)=(a0)x^3 + (a1)x^2 +(a2)x + (a3)'\n\n");
  19. printf("what is the value of a0?\t");
  20. scanf("%d",&p);
  21. printf("what is the value of a1?\t");
  22. scanf("%d",&q);
  23. printf("what is the value of a2?\t");
  24. scanf("%d",&r);
  25. printf("what is the value of a3?\t");
  26. scanf("%d",&s);
  27.  
  28. printf("\n\nWhat is the x value of interval endpoint A?\t");
  29. scanf("%f",&endpointax);
  30. printf("What is the x value of interval endpoint B?\t");
  31. scanf("%f",&endpointbx);
  32.  
  33. printf("\nWhat is the step size?\t");
  34. scanf("%f",&stepsize);
  35.  
  36. n=(endpointbx-endpointax)/stepsize; //to find number of subintervals
  37.  
  38. ay= p* endpointax*endpointax*endpointax + q* endpointax*endpointax + r*endpointax + s;
  39. by= p* endpointbx*endpointbx*endpointbx + q* endpointbx*endpointbx + r*endpointbx + s;
  40. printf("\nA= %.2f,%.2f and B=%.2f,%.2f\n\n",endpointax,ay,endpointbx,by);
  41.  
  42. while(k<=n-1)
  43. {
  44. L=endpointax + k*stepsize;
  45. M=L+stepsize;
  46. ay= p* L*L*L + q* L*L + r*L + s;
  47. by= p* M*M*M + q* M*M + r*M + s;
  48. /*
  49. check_roots(ay,by,endpointbx+k);*/
  50. printf("The %dth interval is %.2f,%.2f to %.2f,%.2f\n",k+1,L,ay,M,by);
  51.  
  52.  
  53. k++;
  54. }
  55.  
  56.  
  57.  
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement