clc; clear; close all;

% Wikipedia example 1 - funkce f(x) = tg(x)
f = @(x) sin(x) ./ cos(x);
nodes = [-1.5, -0.75, 0, 0.75, 1.5];
values = [-14.1014, -0.931596, 0, 0.931596, 14.1014];

% Wikipedia example 2 - funkce f(x) = x^2
%f = @(x) x .^ 2;
%nodes = [1, 2, 3];
%values = [1, 4, 9];

% Wikipedia example 3 - funkce f(x) = x^3
%f = @(x) x .^ 3;
%nodes = [1, 2, 3];
%values = [1, 8, 27];

pol = LagrangePolynomial(nodes, values)

L = min(nodes); R = max(nodes); dx = L:0.01:R;
figure;
plot(nodes, values, 'o', 'Color', 'black', 'LineWidth', 1.5); hold on;
plot(dx, f(dx), 'LineWidth', 1.5, 'Color', 'red'); hold on; % funkce tg(x)
plot(dx, polyval(pol, dx), 'LineWidth', 1.5);