Cant get integral from Lagrange interpolation polynom
Show older comments
I have writed a function to get integral from interpolation Lagrange polynom.
function fxn = lagrange()
clc; clear;
k = [0 1 2 3 4 5 6 7 8 9 10];
xpoints = 0.3 * k;
ypoints = 1 - exp(-xpoints);
L = @(x) 0;
for i = 1 : 11
Li = @(x) 1;
Ld = @(x) 1;
for j = 1 : 11
if i ~= j
Li = @(x) Li(x) * (x - xpoints(j));
Ld = @(x) Ld(x) * (xpoints(i) - xpoints(j));
end
end
L = @(x) L(x) + (Li(x)/Ld(x))*ypoints(i);
end
fprintf("integral from L(x): %f",integral(L, 0, 3));
fxn = @(x) L(x);
end
But when i run this code I have this message appears:
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To
perform elementwise multiplication, use '.*'.
Error in lagrange>@(x)Li(x)*(x-xpoints(j)) (line 12)
Li = @(x) Li(x) * (x - xpoints(j));
Error in lagrange>@(x)Li(x)*(x-xpoints(j)) (line 12)
Li = @(x) Li(x) * (x - xpoints(j));
Error in lagrange>@(x)Li(x)*(x-xpoints(j)) (line 12)
Li = @(x) Li(x) * (x - xpoints(j));
Error in lagrange>@(x)Li(x)*(x-xpoints(j)) (line 12)
Li = @(x) Li(x) * (x - xpoints(j));
Error in lagrange>@(x)Li(x)*(x-xpoints(j)) (line 12)
Li = @(x) Li(x) * (x - xpoints(j));
Error in lagrange>@(x)Li(x)*(x-xpoints(j)) (line 12)
Li = @(x) Li(x) * (x - xpoints(j));
Error in lagrange>@(x)Li(x)*(x-xpoints(j)) (line 12)
Li = @(x) Li(x) * (x - xpoints(j));
Error in lagrange>@(x)Li(x)*(x-xpoints(j)) (line 12)
Li = @(x) Li(x) * (x - xpoints(j));
Error in lagrange>@(x)Li(x)*(x-xpoints(j)) (line 12)
Li = @(x) Li(x) * (x - xpoints(j));
Error in lagrange>@(x)L(x)+(Li(x)/Ld(x))*ypoints(i) (line 16)
L = @(x) L(x) + (Li(x)/Ld(x))*ypoints(i);
Error in lagrange>@(x)L(x)+(Li(x)/Ld(x))*ypoints(i) (line 16)
L = @(x) L(x) + (Li(x)/Ld(x))*ypoints(i);
Error in lagrange>@(x)L(x)+(Li(x)/Ld(x))*ypoints(i) (line 16)
L = @(x) L(x) + (Li(x)/Ld(x))*ypoints(i);
Error in lagrange>@(x)L(x)+(Li(x)/Ld(x))*ypoints(i) (line 16)
L = @(x) L(x) + (Li(x)/Ld(x))*ypoints(i);
Error in lagrange>@(x)L(x)+(Li(x)/Ld(x))*ypoints(i) (line 16)
L = @(x) L(x) + (Li(x)/Ld(x))*ypoints(i);
Error in lagrange>@(x)L(x)+(Li(x)/Ld(x))*ypoints(i) (line 16)
L = @(x) L(x) + (Li(x)/Ld(x))*ypoints(i);
Error in lagrange>@(x)L(x)+(Li(x)/Ld(x))*ypoints(i) (line 16)
L = @(x) L(x) + (Li(x)/Ld(x))*ypoints(i);
Error in lagrange>@(x)L(x)+(Li(x)/Ld(x))*ypoints(i) (line 16)
L = @(x) L(x) + (Li(x)/Ld(x))*ypoints(i);
Error in lagrange>@(x)L(x)+(Li(x)/Ld(x))*ypoints(i) (line 16)
L = @(x) L(x) + (Li(x)/Ld(x))*ypoints(i);
Error in lagrange>@(x)L(x)+(Li(x)/Ld(x))*ypoints(i) (line 16)
L = @(x) L(x) + (Li(x)/Ld(x))*ypoints(i);
Error in lagrange>@(x)L(x)+(Li(x)/Ld(x))*ypoints(i) (line 16)
L = @(x) L(x) + (Li(x)/Ld(x))*ypoints(i);
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 75)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
Error in lagrange (line 23)
fprintf("integral from L(x): %f",integral(L, 0, 3));
What i do wrong? How can i fix this?
2 Comments
John D'Errico
on 3 Mar 2019
A massive misuse of function handles, if I ever saw one?
Valery Kvan
on 3 Mar 2019
Edited: Valery Kvan
on 3 Mar 2019
Accepted Answer
More Answers (0)
Categories
Find more on Interpolation 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!