Guest User

Untitled

a guest
Mar 8th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scilab 0.73 KB | None | 0 0
  1. function solucion=difdiv(f,vector)
  2.     tamanio=size(vector)
  3.     tamanio=tamanio(1,2)
  4.     if (tamanio==1) then
  5.         printf("ERROR TAMAÑO 1")
  6.     else
  7.     if (tamanio==2) then
  8.         solucion=(f(vector(2))-f(vector(1)))/(vector(2)-vector(1))
  9.     else
  10.         v1=vector(2:tamanio)
  11.         v2=vector(1:tamanio-1)
  12.         solucion=(difdiv(f,v1)-difdiv(f,v2))/(vector(tamanio)-vector(1))
  13.     end
  14.     end
  15. endfunction
  16.  
  17. function pol=polinewton(f,v)
  18.     tam=size(v)
  19.     tam=tam(1,2)
  20.     pol=poly(f(v(1)),"x","coef")
  21.     polaux=poly(1,"x","coef")
  22.     for (i=2:tam)
  23.         polcambio=poly(v(i-1),"x")
  24.         polaux=polaux*polcambio
  25.         coef=difdiv(f,v(1:i))
  26.         pol=pol+polaux*coef
  27.     end
  28.    
  29.    
  30. endfunction
Add Comment
Please, Sign In to add comment