mirror of
https://bitbucket.org/Mattrixwv/octavefunctions.git
synced 2025-12-06 18:53:57 -05:00
31 lines
1017 B
Matlab
31 lines
1017 B
Matlab
function [Ln] = LagrangePolynomials(x_data, x)
|
|
%LagrangePolynomials evaluates the entire collection of Lagrange
|
|
%polynomials
|
|
%
|
|
% Input:
|
|
% - x_data: One-dimensional list of x-coordinates of points through
|
|
% which the interpolating polynomial will pass. The degree of the
|
|
% interpolating polynomial, n, will be inferred from the number of
|
|
% entries in x_data
|
|
% - x: One-dimensional list of values for which the Lagrange
|
|
% polynomial will be evaluated
|
|
%
|
|
% Output:
|
|
% -Ln: Matrix of values of Lagrange polynomials of degree n. The
|
|
% matrix has a row for each polynomial and a column for each value of
|
|
% x
|
|
|
|
%Allocate space for the output matrix by initializing it to zero
|
|
|
|
value_count = length(x);
|
|
n = length(x_data) - 1;
|
|
Ln = zeros(n + 1, value_count);
|
|
|
|
%Build each row of the output matrix by evaluating the corresponding
|
|
%polynomial at the x value(s)
|
|
for(k = 0:n)
|
|
Ln(k + 1, :) = LagrangePolynomial(x_data, k, x);
|
|
end
|
|
end
|
|
|