letterbox
Newbie
polynomial reconstruction in matlab
Hi,
I am facing some difficulties with Matlab code for Lagrange polynomial reconstruction.
from the file do_lagranp.m attached:
------------------------------------------
%do_lagranp.m
x = [1 2 3 4 5 6 7 8 9];
res = zeros(size(x));
for i = 1:9
res(i) = 512*x(i)^8 + 102*x(i)^7 + 1024*x(i)^6 + 806*x(i)^5 + ...
216*x(i)^4 + 117*x(i)^3 + 126*x(i)^2 + 132*x(i) + 41584;
end
y = res;
l = lagranp(x,y) %Find the lagrange polynomial
coef = round(l)
----------------------------------------------------------
If I were to use the x values as shown x = [1 2 3 4 5 6 7 8 9], then the code will have no problem in reconstructing the polynomial res by returning the exact coefficients [512 102 1024 806 216 117 .....]
But if I change the x values to something bigger, may be x = [100 200 300 ....],
then the code will not return the correct coefficients anymore.
Can someone please help me? Is there a maximum number that Matlab can only work on? What can I do to solve this issue because I really need the input for data x to be big value.
Thank you!!!
Hi,
I am facing some difficulties with Matlab code for Lagrange polynomial reconstruction.
from the file do_lagranp.m attached:
------------------------------------------
%do_lagranp.m
x = [1 2 3 4 5 6 7 8 9];
res = zeros(size(x));
for i = 1:9
res(i) = 512*x(i)^8 + 102*x(i)^7 + 1024*x(i)^6 + 806*x(i)^5 + ...
216*x(i)^4 + 117*x(i)^3 + 126*x(i)^2 + 132*x(i) + 41584;
end
y = res;
l = lagranp(x,y) %Find the lagrange polynomial
coef = round(l)
----------------------------------------------------------
If I were to use the x values as shown x = [1 2 3 4 5 6 7 8 9], then the code will have no problem in reconstructing the polynomial res by returning the exact coefficients [512 102 1024 806 216 117 .....]
But if I change the x values to something bigger, may be x = [100 200 300 ....],
then the code will not return the correct coefficients anymore.
Can someone please help me? Is there a maximum number that Matlab can only work on? What can I do to solve this issue because I really need the input for data x to be big value.
Thank you!!!