MATLAB: How to use the Output function of a Cubic Spline Interpolation

curve fittingspline

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!

Best Answer

Example:
x = 0:10;
y = 5 + 3*x.^2;
pp = spline(x,y);
int_y = quad(@(xx)ppval(pp,xx),x(1),x(end));
Related Question