-function [pnx] = Lagrange_interpolation(z,)
+function [pnx] = Lagrange_interpolation(z,x,y)
%%
% Implementation to evaluate an interpolating polynomial p_n(x)
% at the point x = z. The polynomial uses the standard Lagrange
% INPUT:
%
% z - 1x1 value to evaluate
-% ???
-%
+% x - nx1 vector with x-values
+% y - nx1 vector with y-valuse
% OUTPUT:
%
% pnx - value of the polynomial interpolant at x = z
%%
% compute the polynomial interpolation sum evaluated at x = z
- pnx =
- for i =
-
-
-
- for j =
-
-
-
+ pnx = 0;
+ n = length(x);
+ l = ones(n,1);
+ for i=1:n
+
+ for j=1:n
+ if i ~= j
+ l(i) = l(i)*(z - x(j))/(x(i) - x(j));
+ end
end
-
- pnx =
+ l(i)
+ pnx = pnx + (y(i) * l(i));
end
end
--- /dev/null
+function [X,L] = build_interpolation(M, xVals, yVals)
+%UNTITLED Summary of this function goes here
+% Detailed explanation goes here
+ X = linspace(xVals(1), xVals(end), M);
+ L = zeros(length(M), 1);
+ for k=1:M
+ L(k) = Lagrange_interpolation(X(k), xVals, yVals);
+ end
+end
\ No newline at end of file
%% EXP
-N = 100;
+N = 1000;
D_x_center = diag(0.5*ones(N,1),1) - diag(0.5*ones(N,1),-1);
D_x_center(1,1) = 1;
f = zeros(length(interval), 1);
f_prim = zeros(length(interval), 1);
for i=1:length(interval)
- f(i) = 4*exp(sin(4*interval(i)));
+ f(i) = exp(sin(4*interval(i)));
f_prim(i) = 4*exp(sin(4*interval(i)))*cos(4*interval(i));
end
-D_x_center
-interval
-f
-approx = (1/h) * D_x_center * f
-f_prim
+approx_mid = (1/h) * D_x_center * f;
+%approx_edge = (1/h) * D_x_forward * f;
+%approx_mid(1) = approx_edge(1);
+%approx_mid(end) = approx_edge(end);
+
+bound_low = ((-3*f(1)) + (4*f(2)) - (f(3)))/(2*h);
+bound_up = ((f(N-2)) - (4*f(N-1)) + (3*f(N)))/(2*h);
+
+approx_mid(1) = bound_low;
+approx_mid(end) = bound_up;
+
+max(abs(f_prim - approx_mid))
+
--- /dev/null
+xVals = [1, 2, 3, 4, 5];
+yVals = [1, 1, 2, 6, 24];
+[X, L] = build_interpolation(150, xVals, yVals);
+%plot(X, gamma(X), '-k' , X, L, '--r', xVals, yVals, 'rd', 'MarkerFaceColor', 'r', 'MarkerSize', 7)
+
+p = Lagrange_interpolation(6, xVals, yVals)
+q = gamma(6)
+sqrt(pi)/2
+
+%%
+
+xVals = x_joukow;
+yVals = y_joukow;
+[X, L] = build_interpolation(150, xVals, yVals);
+
+M = linspace(-1.775, 1.695, 150);
+s = spline(x_joukow, y_joukow, M);
+
+
+plot(X, L, '--r', xVals, yVals, 'rd', 'MarkerFaceColor', 'r', 'MarkerSize', 7)
+plot(M, s, '-.g', 'LineWidth', 2);
\ No newline at end of file