Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Laborator SD
- http://geeksquiz.com/binary-search-tree-set-2-delete/
- MN:
- Neville:
- function [yi, P] = neville(x, y, xi)
- n = length(x);
- yi = zeros(1, length(xi));
- P = zeros(n, n);
- P(:, 1) = y;
- for k = 1 : length(xi)
- for i = 1 : n - 1
- for j = 1 : (n - i)
- P(j, i + 1) = ((xi(k) - x(j)) * P(j + 1, i) + (x(j + i) - xi(k)) * P(j, i))/(x(j + i) - x(j));
- end
- end
- yi(k) = P(1, n);
- end
- end
- Natural Spline:
- function [s0,s1,s2,s3]=cubic_spline(x,y)
- n = length(x);
- h = x(2:n) - x(1:n-1);
- d = (y(2:n) - y(1:n-1))./h;
- lower = h(1:end-1);
- main = 2*(h(1:end-1) + h(2:end));
- upper = h(2:end);
- if n==2
- m=0;
- else
- T = spdiags([lower main upper], [-1 0 1], n-2, n-2);
- rhs = 6*(d(2:end)-d(1:end-1));
- m = T\rhs;
- end
- % Use natural boundary conditions where second derivative
- % is zero at the endpoints
- m = [ 0; m; 0];
- s0 = y;
- s1 = d - h.*(2*m(1:end-1) + m(2:end))/6;
- s2 = m/2;
- s3 =(m(2:end)-m(1:end-1))./(6*h);
- end
- Plot Natural Spline:
- function yy = plot_cubic_spline(x,y,xx)
- n = length(xx);
- [s0, s1, s2, s3] = naturalspline(x', y');
- yy = zeros(1, n);
- for j = 1 : n
- for k = 1 : length(x)
- if xx(j) < x(k)
- break;
- end
- end
- i = k - 1;
- yy(j) = s0(i) + s1(i) * (xx(j) - x(i)) + s2(i) * (xx(j) - x(i)).^2 + s3(i) * (xx(j) - x(i)).^3;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement