Lagrange Interpolation code error

2 Ansichten (letzte 30 Tage)
Charitha Heshan
Charitha Heshan am 28 Mär. 2018
Beantwortet: Roger Stafford am 28 Mär. 2018
Please tell me whats wrong with this code, it was given by the professor but when i try to use it it gives me errors.
if true
function yi = LagrangeInterp(x,y,xi)
x = [ -0.200 0.000 0.200 0.400 0.600 0.800 1.000]; y = [ 0.5000 1.0000 0.5000 0.2000 0.1000 0.0588 0.0385 ];
n = length (x) ; L = zeros (1,n) ; for i =1:n, L(i) = 1; for j = 1:n, if j ~= i, L(i) = L(i) * (xi - x(j)) / (x(i) - x(j)); end end end
yi = sum(y.*L);
% code
end
*Not enough input values *Error in line 3
I want to find Y values when x= 0.3 & x = 0.9
please give me a correct method to find this .
thank you

Antworten (1)

Roger Stafford
Roger Stafford am 28 Mär. 2018
The message is caused by your not defining or properly entering the value of vector 'xi'.

Kategorien

Mehr zu Interpolation 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