rorschack

QT_Prac_NewtonsForward_2A

Mar 1st, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 0.55 KB | None | 0 0
  1. /*
  2. x=[45 50 55 60 65]
  3. y=f(x)=[29 24 21 19 17]
  4. x estimate = 46
  5. Ans:
  6.    27.792
  7. */
  8.  
  9. function[] = newton_fwd(x,y,xest)
  10.     n=length(y)
  11.     h=x(2)-x(1)
  12.     u=(xest-x(1))/h
  13.     e(1)=u
  14.     for i=1:n-1
  15.         d(i,1)=y(i+1)-y(i)
  16.     end
  17.     for j=2:n
  18.         for i=1:n-j
  19.             d(i,j)=d(i+1,j-1)-d(i,j-1)
  20.         end
  21.         e(j)=e(j-1)*(u+1-j)/j
  22.     end
  23.     yest=0;
  24.     for j=1:n-1
  25.         yest=yest+e(j)*d(1,j)
  26.     end
  27.     yest=yest+y(1)
  28.     disp(yest)
  29. endfunction
  30.  
  31. x=[45 50 55 60 65]
  32. y=[29 24 21 19 17]
  33. xest=46
  34. newton_fwd(x,y,xest)
Add Comment
Please, Sign In to add comment