Docsity

Integration (numerical computing), Study notes of Mathematics

Toggle sidebar
bg1
Notes Prepared By: Engineer M.Rehan Saleem (engineer_rehan1[email protected])
Course Numerical Computing
Integration Notes (Matlab Method)
integral
Numerically evaluate integral
Syntax
q = integral(fun,xmin,xmax)
Examples
Evaluate Improper Integral
Create the anonymous function f(x) = e-x2(ln x)2.
fun = @(x) exp(-x.^2).*log(x).^2;
Evaluate the integral from x=0 to x=Inf.
q = integral(fun,0,Inf)
q =
1.9475
Integrate Parameterized Function
Create the anonymous function f(x) = 1/(x3 – 2x – c) with one parameter, c.
fun = @(x,c) 1./(x.^3-2*x-c);
Evaluate the integral from x=0 to x=2 at c=5.
q = integral(@(x)fun(x,5),0,2)
q =
-0.4605
pf3
pf4
pf5

Partial preview of the text

Download Integration (numerical computing) and more Study notes Mathematics in PDF only on Docsity!

Notes Prepared By: Engineer M.Rehan Saleem ([email protected])

Course Numerical Computing

Integration Notes (Matlab Method)

integral

Numerically evaluate integral

Syntax

 q = integral(fun,xmin,xmax)

Examples

Evaluate Improper Integral

Create the anonymous function f ( x ) = e - x^2 (ln x )^2.

fun = @(x) exp(-x.^2).*log(x).^2;

Evaluate the integral from x=0 to x=Inf.

q = integral(fun,0,Inf) q =

Integrate Parameterized Function

Create the anonymous function f ( x ) = 1/( x^3 – 2 x – c ) with one parameter, c.

fun = @(x,c) 1./(x.^3-2*x-c);

Evaluate the integral from x=0 to x=2 at c=5.

q = integral(@(x)fun(x,5),0,2) q =

-0.

Evaluate Integral with Singularity at the Lower Limit of Integration

Create the anonymous function f ( x ) = ln( x ).

fun = @(x)log(x);

Evaluate the integral from x=0 to x=1 with the default error tolerances.

q1 = integral(fun,0,1) q1 =

-1.

Complex Contour Integration Using Waypoints

Specify waypoints [1+1i,1-1i] to integrate over the triangular path: 0 to 1+1i to 1-1i to 0.

Create the anonymous function f ( z ) = 1/(2 z – 1).

fun = @(z) 1./(2*z-1);

Integrate in the complex plane over the triangular path from 0 to 1+1i to 1-1i to 0.

q = integral(fun,0,0,'Waypoints',[1+1i,1-1i]) q =

0 - 3.1416i

Integrate Vector-Valued Function

Specify 'ArrayValued',true to evaluate the integral of an array-valued or vector-valued

function.

Create the anonymous vector-valued function f ( x ) = [sin x , sin 2 x , sin 3 x , sin 4 x , sin 5 x ] and

integrate from x=0 to x=1.

fun = @(x)sin((1:5)*x); q = integral(fun,0,1,'ArrayValued',true) q =

0.4597 0.7081 0.6633 0.4134 0.

Improper Integral of an Oscillatory Function

Create the anonymous function f ( x ) = x^5 e- x^ sin x.

fun = @(x)x.^5.exp(-x).sin(x);

Evaluate Double Integral in Polar Coordinates

Define the function

fun = @(x,y) 1./( sqrt(x + y) .* (1 + x + y).^2 ); polarfun = @(theta,r) fun(r.cos(theta),r.sin(theta)).*r;

Define a function for the upper limit of r.

rmax = @(theta) 1./(sin(theta) + cos(theta));

Integrate over the region bounded by 0 ≤ θ ≤ π /2 and 0 ≤ r ≤ rmax.

q = integral2(polarfun,0,pi/2,0,rmax) q =

Evaluate Double Integral of Parameterized Function with Specific Method and Error Tolerance

Create the anonymous parameterized function f ( x , y ) = ax^2 + by^2 with parameters a =3 and b =5.

a = 3; b = 5; fun = @(x,y) ax.^2 + by.^2;

Evaluate the integral over the region 0 ≤ x ≤ 5 and -5 ≤ y ≤ 0. Specify the 'iterated' method

and approximately 10 significant digits of accuracy.

q = integral2(fun,0,5,-5,0,'Method','iterated',... 'AbsTol',0,'RelTol',1e-10) q =

1.666666666666666e+

integral

Numerically evaluate triple integral

Syntax

 q = integral3(fun,xmin,xmax,ymin,ymax,zmin,zmax)

Description

q = integral3(fun,xmin,xmax,ymin,ymax,zmin,zmax) approximates the integral of the

function z = fun(x,y,z) over the region xmin ≤ x ≤ xmax, ymin(x) ≤ y ≤ ymax(x) and

zmin(x,y) ≤ z ≤ zmax(x,y).

Examples

Triple Integral with Finite Limits

Define the anonymous function f ( x , y , z ) = y sin x + z cos x.

fun = @(x,y,z) y.sin(x)+z.cos(x)

Integrate over the region 0 ≤ x ≤ π , 0 ≤ y ≤ 1, and - 1 ≤ z ≤ 1.

q = integral3(fun,0,pi,0,1,-1,1) q =

Integral Over the Unit Sphere in Cartesian Coordinates

Define the anonymous function f ( x , y , z ) = x cos y + x^2 cos z.

fun = @(x,y,z) x.cos(y) + x.^2.cos(z)

Define the limits of integration.

xmin = -1; xmax = 1; ymin = @(x)-sqrt(1 - x.^2); ymax = @(x) sqrt(1 - x.^2); zmin = @(x,y)-sqrt(1 - x.^2 - y.^2); zmax = @(x,y) sqrt(1 - x.^2 - y.^2);

Evaluate the definite integral with the 'tiled' method.

q = integral3(fun,xmin,xmax,ymin,ymax,zmin,zmax,'Method','tiled') q =

Evaluate Improper Triple Integral of Parameterized Function

Define the anonymous parameterized function f ( x , y , z ) = 10/( x^2 + y^2 + z^2 + a ).

a = 2; f = @(x,y,z) 10./(x.^2 + y.^2 + z.^2 + a);