Skip to content

Instantly share code, notes, and snippets.

@vertexclique
Created June 4, 2011 09:52
Show Gist options
  • Save vertexclique/1007764 to your computer and use it in GitHub Desktop.
Save vertexclique/1007764 to your computer and use it in GitHub Desktop.
Derive an equation from point like (x,y), its arguments are x=[x0,x1,...,yn] and y=[y0,y1,...,yn]
function interpolation(x,y)
boyut = length(x);
for i=1:boyut
for j=1:boyut
if( j==1) mat(i,j) = 1;
continue;
end;
mat(i,j) = x(i)^(j-1);
end;
end;
a = pinv(mat)*(y');
syms x;
k=0;
for j = length(a):-1:1
k = k + a(j)*x^(j-1);
end;
pretty(k);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment