Interpolate function using Spline and Lagrange interpolation and take definite integral from it
Show older comments
I have the function f(x) = 1 - exp(-x); xk = 0.3*k; k = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; integral from 0 to 3; I have found how take integral from f(x), spline function. I have not found lagrange function. How i can take integral from spline function and how i can interpolate with lagrange and then take integral from it.
when i take integral from spline i have this message in command windows
Error using integralCalc/finalInputChecks (line 522)
Input function must return 'double' or 'single' values. Found 'struct'.
Error in integralCalc/iterateScalarValued (line 315)
finalInputChecks(x,fx);
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 lab1 (line 19)
clc;
clear;
k = [0 1 2 3 4 5 6 7 8 9 10];
xpoints = 0.3 * k;
ypoints = 1 - exp(-xpoints);
%f(x) function and integral
f = @(x) 1 - exp(-x);
fplot(f, [0 3.0]);
grid on;
integralFx = integral(f, 0, 3);
fprintf("%f\n", integralFx);
%s(x)
f(xpoints);
s = @(x) spline(xpoints, ypoints);
integral (s, 0, 3);
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!