mirror of
https://bitbucket.org/Mattrixwv/octavefunctions.git
synced 2025-12-07 03:03:57 -05:00
From Numerical Analysis 10-10-18
This commit is contained in:
30
LagrangePolynomials.m
Normal file
30
LagrangePolynomials.m
Normal file
@@ -0,0 +1,30 @@
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user