How to use the Output function of a Cubic Spline Interpolation?
Mostrar comentarios más antiguos
I'm supposed to use cubic spline interpolation to approximate a function such as: exp(-1*(X^2)) then integrate the approximated function using different methods.
What I've been able to do so far is this: x=-10:1:10 y=exp(-1*(x.^2)); plot(x,y)
Then using the Curve fitting toolbox the approximated function shown on the graph is: y=-483e-020*x^3 - 0.00286*x^2+4.54e-018*x+0.18
How can I get the same function as an output in order to use it in the integration? Thanks in Advance!
Respuesta aceptada
Más respuestas (2)
Mike Hosea
el 28 de Dic. de 2011
Just wanted to add that the best way of integrating a piecewise-defined function in MATLAB is
quadgk(@(t)ppval(pp,t),x(1),x(end),'Waypoints',x)
where x is, as in the above examples, the vector of locations where the pieces of the function are joined. Supplying these "waypoints" to QUADGK allows it to integrate efficiently over any discontinuities or limited smoothness where the pieces are joined. If there is, in fact, some of that limited smoothness there, you will typically find that using QUADGK like that is significantly faster and more accurate.
Christopher Crawford
el 4 de En. de 2023
Piecewise polynomials like cubic splines can be integrated analytically. This is implemented by 'ppint' (8ve), or 'fnint' (Curvefitting Toolbox), see https://www.mathworks.com/matlabcentral/answers/394457-piecewise-polynomial-integration-ppint
diff(ppval( ppint(pp), x([1,end]) ))
Categorías
Más información sobre Splines en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!