Cant get integral from Lagrange interpolation polynom
Afficher commentaires plus anciens
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 commentaires
John D'Errico
le 3 Mar 2019
A massive misuse of function handles, if I ever saw one?
Valery Kvan
le 3 Mar 2019
Modifié(e) : Valery Kvan
le 3 Mar 2019
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Interpolation dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!