Main Content

integrate

Integrate cfit object

Description

int = integrate(fun,x,x0) integrates the cfit object fun at the points specified by the vector x, starting from x0, and returns the result in int.

example

Examples

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 method
subplot(2,1,2)
plot(xdata,int,'m') % double plot method
grid on
legend('integral')

Figure contains 2 axes objects. Axes object 1 with xlabel x, ylabel y contains 2 objects of type line. One or more of the lines displays its values using only markers These objects represent Data, Fitted curve. Axes object 2 contains an object of type line. This object represents integral.

You can also compute integrals and plot them directly with the cfit plot method:

figure
plot(fit1,xdata,ydata,{'fit','integral'})

Figure contains 2 axes objects. Axes object 1 with xlabel x, ylabel y contains 2 objects of type line. One or more of the lines displays its values using only markers These objects represent Data, Fitted curve. Axes object 2 with xlabel x contains an object of type line. This object represents Integral from 0 to x.

The plot method, however, does not return data on the integral.

Input Arguments

collapse all

Function to integrate, specified as a cfit object.

Points at which to integrate the function, specified as a numeric vector.

Lower bound for integration, specified as a numeric scalar.

Output Arguments

collapse all

Result of the integration, returned as a numeric vector of the same size as x.

Version History

Introduced before R2006a