Lagrange Interpolating Polynomial Function

2 Ansichten (letzte 30 Tage)
Robin McManus
Robin McManus am 20 Nov. 2020
Beantwortet: Alan Stevens am 20 Nov. 2020
I'm trying to write MATLAB code that outputs a Lagrange Interpolating Polynomial. I'll include my code below, although its definitely not refined yet. I was planning on making an array of functions, but I just noticed that matlab doesn't accept functions in arrays. Is there a way around this?
x = [-1 2 3 5]
y = [0 1 1 2]
n = length(x)
f = @(x) x;
array = ones(1,(n-1));
for k = 0: n-1
for i = 0 : n-1
if i ~= k
array(k) = array(k) * (f(x)-x(i))/(x(k)-x(i))
end
end
end
array

Antworten (1)

Alan Stevens
Alan Stevens am 20 Nov. 2020
Matlab indexing starts from 1 not zero. Also, in
array(k) = array(k) * (f(x)-x(i))/(x(k)-x(i))
you should have f(x(i)) not f(x).

Kategorien

Mehr zu Polynomials finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by