Advertisement
wieschoo

Untitled

Apr 30th, 2014
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.83 KB | None | 0 0
  1. %Interpolation nach Newton. Rungebeispiel mit aequidistanten Stuetzstellen.
  2. clc
  3. NumberOfData= 25;
  4. SamplingPoints = linspace(-1,1,NumberOfData); %Generieren der n Stützstellen.
  5. f = @(x) 1./(1+25.*x.*x); %Runge-Beispiel
  6.  
  7. TargetValues = f(SamplingPoints); %Dividierte Differenzen
  8.  
  9. for k=1:NumberOfData
  10.     h(k) = TargetValues(k);
  11.     if k>1
  12.         for i=k-1:-1:1
  13.             h(i) = (h(i+1)-h(i)) ./(SamplingPoints(k)-SamplingPoints(:,i));
  14.         end
  15.     end
  16.     p(k) = h(1);
  17. end
  18.  
  19. % zurück rechnen
  20. n = NumberOfData;
  21. vls = p(:,n)*ones(1,NumberOfData);
  22. for i = NumberOfData-1:-1:1
  23.     vls = vls.*(SamplingPoints-SamplingPoints(i)*ones(1,NumberOfData))+p(:,i)*ones(1,NumberOfData);
  24. end
  25.  
  26.  
  27. % links
  28. plot(SamplingPoints,TargetValues,'r');
  29. hold on
  30. plot(SamplingPoints,vls,'.k');
  31. legend('original Fkt','newton. Interp.');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement