DocumentationHelp Center
integrate
Integratecfitobject
cfit
int = integrate(fun,x,x0)
example
int= integrate(fun,x,x0)integrates thecfitobjectfunat the points specified by the vectorx, starting fromx0, and returns the result inint.
int= integrate(fun,x,x0)
int
fun
x
x0
collapse all
Create a baseline sinusoidal signal.
xdata = (0:.1:2*pi)'; y0 = sin(xdata);
Add response-dependent Gaussian noise to the signal.
noise = 2*y0.*randn(size(y0)); ydata = y0 + noise;
Fit the noisy data with a custom sinusoidal model.
f = fittype('a*sin(b*x)'); fit1 = fit(xdata,ydata,f,'StartPoint',[1 1]);
Find the integral of the fit at the predictors.
int = integrate(fit1,xdata,0);
Plot the data, the fit, and the integral.
subplot(2,1,1) plot(fit1,xdata,ydata)% cfit plot methodsubplot(2,1,2) plot(xdata,int,'m')% double plot methodgridonlegend('integral')
You can also compute integrals and plot them directly with thecfitplotmethod:
plot
figure plot(fit1,xdata,ydata,{'fit','integral'})
Theplotmethod, however, does not return data on the integral.
Function to integrate, specified as acfitobject.
Points at which to integrate the function, specified as a vector.
First point of integration, specified as a scalar.
Result of the integration, returned as a vector of the same size ofx.
differentiate|fit|plot
differentiate
fit
A modified version of this example exists on your system. Do you want to open this version instead?
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office