SHARE
TWEET

Untitled

a guest Nov 18th, 2014 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. const int n = 6;
  5.  
  6. double func_val (double x, double* x_val, double* y_val){
  7.         double newt_val = 0;
  8.         double div_diff, denom;
  9.  
  10.         for (int i = 0; i < n; i++){
  11.                 div_diff = 0;
  12.                 for (int j = 0; j <= i; j++){
  13.                         denom = 1;
  14.                                 for (int k = 0; k <= i; k++){
  15.                                         if (k != j) denom *= (x_val[j] - x_val[k]);
  16.                                         printf("%f \n", denom);
  17.                                 }
  18.                                 div_diff += y_val[j] / denom;
  19.                 }
  20.                 for (int k = 0; k < i; k++) div_diff *= (x - x_val[k]);
  21.                 newt_val += div_diff;
  22.         }
  23.         return newt_val;
  24. }
  25.  
  26. double F(double x) { return pow(x, 2)* 0.6; }
  27.  
  28. int main () {
  29.         double x_val[n];
  30.         double y_val[n];
  31.         double s, j = 2;
  32.  
  33.         for (int i = 0; i < n; i++)
  34.         {
  35.                 x_val[i] = j;
  36.                 y_val[i] = F(j);
  37.                 j += 1.0 / (n - 1);
  38.         }
  39.  
  40.         s = abs(F(0.5) - func_val(0.5 , x_val, y_val));
  41.         printf ("%lf\nerror: %lf", func_val(0.5, x_val, y_val), s);
  42.         getchar();
  43.         return 0;
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top