Find the missing values using Lagrange polynomials
4 views (last 30 days)
Show older comments
First of all , I am finding three missing values in my data. Second, I need to find the value of the mean carbon dioxide measurement on specific data. I put lagrange(x,pointx,pointy), but it just keep come up a wrong number(386.9400).
clc;
clear;
load C02Data.mat;
x = C02Data(:,2);
pointx = C02Data(:,2);
pointy = C02Data(:,3);
lagrange(x,pointx,pointy)
function y=lagrange(x,pointx,pointy)
n=size(pointx,2);
L=ones(n,size(x,2));
if (size(pointx,2)~=size(pointy,2))
fprintf(1,'\nERROR!\nPOINTX and POINTY must have the same number of elements\n');
y=NaN;
else
for i=1:n
for j=1:n
if (i~=j)
L(i,:)=L(i,:).*(x-pointx(j))/(pointx(i)-pointx(j));
end
end
end
y=0;
for i=1:n
y=y+pointy(i)*L(i,:);
end
end
0 Comments
Answers (0)
See Also
Categories
Find more on Polynomials in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!