求一个matlab中离散一元函数积分的方法

求一个matlab中离散一元函数积分的方法,不能用matlab现成的函数,最好是像梯形法这种但是要用抛物线代替梯形中的斜边来提高精度

用值积分,
输入 doc quad 看看帮助和例子就知道了。
Syntax

q = quad(fun,a,b)
q = quad(fun,a,b,tol)
q = quad(fun,a,b,tol,trace)
[q,fcnt] = quad(...)
Description

Quadrature is a numerical method used to find the area under the graph of a function, that is, to compute a definite integral.

q = quad(fun,a,b) tries to approximate the integral of function fun from a to b to within an error of 1e-6 using recursive adaptive Simpson quadrature. fun is a function handle. See Function Handles in the MATLAB Programming documentation for more information. Limits a and b must be finite. The function y = fun(x) should accept a vector argument x and return a vector result y, the integrand evaluated at each element of x.

Parametrizing Functions, in the MATLAB Mathematics documentation, explains how to provide additional parameters to the function fun, if necessary.

q = quad(fun,a,b,tol) uses an absolute error tolerance tol instead of the default which is 1.0e-6. Larger values of tol result in fewer function evaluations and faster computation, but less accurate results. In MATLAB version 5.3 and earlier, the quad function used a less reliable algorithm and a default relative tolerance of 1.0e-3.

q = quad(fun,a,b,tol,trace) with non-zero trace shows the values of [fcnt a b-a Q] during the recursion.

[q,fcnt] = quad(...) returns the number of function evaluations.

The function quadl may be more efficient with high accuracies and smooth integrands.

The list below contains information to help you determine which quadrature function in MATLAB to use:

*

The quad function may be most efficient for low accuracies with nonsmooth integrands.
*

The quadl function may be more efficient than quad at higher accuracies with smooth integrands.
*

The quadgk function may be most efficient for high accuracies and oscillatory integrands. It supports infinite intervals and can handle moderate singularities at the endpoints. It also supports contour integration along piecewise linear paths.
*

The quadv function vectorizes quad for an array-valued fun.
*

If the interval is infinite, [a,Inf), then for the integral of fun(x) to exist, fun(x) must decay as x approaches infinity, and quadgk requires it to decay rapidly. Special methods should be used for oscillatory functions on infinite intervals, but quadgk can be used if fun(x) decays fast enough.
*

The quadgk function will integrate functions that are singular at finite endpoints if the singularities are not too strong. For example, it will integrate functions that behave at an endpoint c like log|x-c| or |x-c|p for p >= -1/2. If the function is singular at points inside (a,b), write the integral as a sum of integrals over subintervals with the singular points as endpoints, compute them with quadgk, and add the results.

Example

To compute the integral

write an M-file function myfun that computes the integrand:

function y = myfun(x)
y = 1./(x.^3-2*x-5);

Then pass @myfun, a function handle to myfun, to quad, along with the limits of integration, 0 to 2:

Q = quad(@myfun,0,2)

Q =

-0.4605

Alternatively, you can pass the integrand to quad as an anonymous function handle F:

F = @(x)1./(x.^3-2*x-5);
Q = quad(F,0,2);

Algorithm

quad implements a low order method using an adaptive recursive Simpson's rule.
Diagnostics

quad may issue one of the following warnings:

'Minimum step size reached' indicates that the recursive interval subdivision has produced a subinterval whose length is on the order of roundoff error in the length of the original interval. A nonintegrable singularity is possible.

'Maximum function count exceeded' indicates that the integrand has been evaluated more than 10,000 times. A nonintegrable singularity is likely.

'Infinite or Not-a-Number function value encountered' indicates a floating point overflow or division by zero during the evaluation of the integrand in the interior of the interval.
温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-05-04
离散函数,就在散点处,用sigma
∑求和就行了。
相似回答