leftimage for poohprod.ru

Learn to solve definite integrals with a numerical software

How to calculate integrals with Matlab



In computerized or numerical methods, a numerical integration can be performed by a number of algorithms that calculate the approximate value of definite integrals.

Numerical evaluation of the integral definite integral to be performed by Matlab is called quadrature. The term ‘numerical quadrature’ is more or less a synonym for numerical integration, especially if applied to one-dimensional integrals.

We’re going to focus this time on the calculation of definite integrals using the Matlab already built-in functions.


Why we can evaluate definite integrals

There’s a number of reasons for carrying out numerical integration. The integrand f(x) may be known only at certain points, such as obtained by sampling. Some digital systems and other computer applications may need integral calculus for this reason.

A formula for the integrand could be known, but it may be difficult or impossible to find an analytical integral.

It may be possible to find an antiderivative, but it may be easier to compute a numerical approximation. That may be the case if the exact integral is given as an infinite series, or if its evaluation requires a special function which is not available.

Matlab provides the following built-in functions for numerical integration:

quad - Uses adaptive Simpson quadrature.

Basic form: q = quad(FUN, A, B), which tries to approximate the integral of scalar-valued function FUN from A to B to within an error of 1 x 10-6 using recursive adaptive Simpson quadrature. The function Y = f(X) should accept a vector argument X and return a vector result Y, the integrand evaluated at each element of X.

quadl – Uses adaptive Lobatto quadrature.

Basic form: q = quadl(FUN, A, B), which tries to approximate the integral using high order recursive adaptive quadrature.

Let’s work on some examples and learn a little bit about intgral calculus...


Single integration

The Gaussian integral (aka Euler-Poisson integral or Poisson integral) is the integral of the Gaussian function over the entire real numbers.


Gaussian integral to be solved with Matlab

Since the result is exact for a known interval, let’s use this function as a guinea pig.

First, let’s plot it to see what we’re doing. We cannot go from -infinity to infinity, but we can use a more reasonable interval.

x = -7 : .1 : 7;
y = exp(-x.^2);
plot(x, y)

and we get

Gaussian curve - definite integrals

Now, we see that if we integrate in the interval [-8, 8] we can get a very good answer. We don’t have to go beyond that.

You can define a separate function for the integrand, and use its name within the quad function. In this case, the expression is simple and we’re going to use it directly as an argument to the quadrature

format long
y1 = quad('exp(-x.^2)', -8, 8)
y2 = quad(
'exp(-x.^2)', -20, 20)

and the answers are

y1 = 41
y2 = 36

Obviously, the second answer is better than the first one (according to sqrt(pi)), due to the longer interval, but even the first answer is correct to 5 digits.

You can type help quad or help quadl on your Matlab command window to see a full description of the usage and examples of the functions.


Double integration

To evaluate definite integrals of the form

definite integrals - double integration

there’s the function dblquad. The basic syntax for double integration is:

II = dblquad(‘fxy_fun’, x_min, x_max, y_min, y_max)

Let’s compute the following double integral

double integrals - example

f = inline('x.^2 + 4*y');
ii = dblquad(f, 11, 14, 7, 10)

and the result is 1719


From 'Definite Integrals' to home

From 'Definite Integrals' to 'Calculus Problems'

Trapezium Rule

Simpson's Rule

Derivatives

Series and sequences

Top




footer for matlab page





Related pages


pythagorean calculatorconvert letters to asciimatlab linear algebra tutorialcontinuous interest rate calculatorohms law caculatorexpansion of sine seriesgauss-jordan elimination step by stephow to convert octal to decimalwrite a function in matlabmatlab hobjectrc circuit simulatorconvert decimal to binary codehow to find time constant in rc circuithow to write unit step function in matlabbinary to gray code calculatorbinary to octal conversion formulaconverting ascii to charscilab programming tutorialpythagorean theorem right triangle calculatormatlab plot exponential functionhow to graph a piece wise functiongui matlab exampleguide matlab examplesconvert cartesian coordinates to polarsawtooth wavesscilab matlabfive band resistorgui tutorial matlabpie chart matlabmatlab exponential curve fitmatrix card trickslope given two points calculatorsawtooth function equationcombinational logic gatesfor loop matrix matlabx axis matlabmortgage amortisationlaptop depreciation rateconverting binary to hexinverse function matlabascii char mapmatlab drawingmatlab forumsboolean algebra tutorial pdfmatlab forumhow to create a table in matlabdetermining salvage valuehow to change from binary to decimalsimple matlab gui examplesdefinition of a piecewise functionmatlab curve fittinghex binary chartspline curve fitting matlabmatlab plot 2d matrixcalculator quadratic formula programonline graphing calculator piecewise functionsrecursion programintegral calculator definitetotal value annuityconvert from binary to hexadecimalfibonaci series programpermutation and combination calculatorconvert from ascii to charexpansion of sine seriessalvage value of a carlagrange polynomial interpolation matlab codesalvage value calculatorwhat does piecewise meanhow to convert to binary from decimaltrendline matlabmatlab trapezoidal methodmatlab divisionhow convert binary to decimaldiscrete distribution calculatorpythagorean calculatorbisection method using matlabpascal triangle codehow to call matlab functiongauss curve