Created
April 4, 2012 21:08
-
-
Save carbolymer/2305689 to your computer and use it in GitHub Desktop.
Interpolacja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clear; | |
global n = 50; | |
x = sort(rand(1,n).*10); | |
y = rand(1,n).*20-10; | |
function f = nwtn(x,known_x,a) | |
global n; | |
f = 0; | |
for i=1:n | |
elem = a(i); | |
for j=1:i-1 | |
elem = elem * (x-known_x(j)); | |
endfor | |
f = f + elem; | |
endfor | |
endfunction | |
for i=1:n | |
a = y; | |
for j=2:n | |
for k=n:-1:j | |
a(k)=(a(k)-a(k-1))/(x(k)-x(k-j+1)); | |
endfor | |
endfor | |
endfor | |
xx = -1:0.01:11; | |
i = 0; | |
for x_=xx | |
yy(++i) = nwtn(x_,x,a); | |
endfor | |
plot(x,y,"x","markersize", 20,xx,yy); | |
axis([0, 11, -11, 11]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment