Sunteți pe pagina 1din 6

int(h,0,2) Y = diff(X,n) applies diff recursively n times, resulting in the nth difference.

Thus, diff(X,2) is the


same as diff(diff(X))

double (standing for double-precision number) double(int(h,0,2)) quadl() quadl(inline(vectorize(h)),0,2)

Find the derivatives

The derivative of the product

is obtained with a = [3 6 9]; b = [1 2 0]; k = polyder(a,b) k = 12 36 42 18 This result represents the polynomial

[q,d] = polyder(b,a) returns the numerator q and denominator d of the derivative of the polynomial
quotient b/a Create the anonymous function f(x) = e-x (ln x)2.
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

integral
Numerically evaluate integral

Syntax

q = integral(fun,xmin,xmax)example q = integral(fun,xmin,xmax,Name,Value)example Description


example

q = integral(fun,xmin,xmax) approximates the integral of function fun from xmin to xmax using global adaptive quadrature and default error tolerances.
example

q = integral(fun,xmin,xmax,Name,Value) specifies additional options with one or more Name,Value pair arguments.

Examples
collapse all

Evaluate Improper Integral


Create the anonymous function f(x) = e-x (ln x)2.
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
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.

format long q1 = integral(fun,0,1) q1 = -1.000000010959678


Evaluate the integral again, specifying approximately 12 decimal places of accuracy.

q2 = integral(fun,0,1,'RelTol',0,'AbsTol',1e-12) q2 = -1.000000000000010
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/(2z 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 2x, sin 3x, sin 4x, sin 5x] 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.1433


Improper Integral of an Oscillatory Function
Create the anonymous function f(x) = x5 e-x sin x.

fun = @(x)x.^5.*exp(-x).*sin(x);
Evaluate the integral from x=0 to x=Inf , adjusting the absolute and relative tolerances.

format long q = integral(fun,0,Inf,'RelTol',1e-8,'AbsTol',1e-13) q = -14.999999999998364

integral2
Numerically evaluate double integral

Syntax

q = integral2(fun,xmin,xmax,ymin,ymax)example q = integral2(fun,xmin,xmax,ymin,ymax,Name,Value) example Description


example

= integral2(fun,xmin,xmax,ymin,ymax) approximates the integral of the function z = fun(x,y) over the planar region xmin x xmax and ymin(x) y ymax(x).
q
example

q = integral2(fun,xmin,xmax,ymin,ymax,Name,Value) specifies additional options with one or moreName,Value pair arguments.

Examples
collapse all

Integrate Triangular Region with Singularity at the Boundary


The function

is undefined when x and y are zero. boundary. Create the anonymous function.

integral2 performs best when singularities are on the integration

fun = @(x,y) 1./( sqrt(x + y) .* (1 + x + y).^2 )


Integrate over the triangular region bounded by 0 x 1 and 0 y 1 x.

ymax = @(x) 1 - x q = integral2(fun,0,1,0,ymax) q = 0.2854


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 = 0.2854
Evaluate Double Integral of Parameterized Function with Specific Method and Error Tolerance
Create the anonymous parameterized function f(x,y) = ax2 + by2 with parameters a=3 and b=5.

a = 3; b = 5; fun = @(x,y) a*x.^2 + b*y.^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.

format long q = integral2(fun,0,5,-5,0,'Method','iterated',... 'AbsTol',0,'RelTol',1e-10) q = 1.666666666666666e+03

S-ar putea să vă placă și