整合(或也叫作集成)涉及兩種本質(zhì)上不同類型的問題。
確定的積分用于查找區(qū)域,體積,重心,轉(zhuǎn)動(dòng)慣量,由力完成的工作以及許多其他應(yīng)用。
根據(jù)定義,如果函數(shù)f(x)的導(dǎo)數(shù)是f'(x),那么可以說f'(x)相對(duì)于x的不確定積分是f(x)。 例如,由于x^2的導(dǎo)數(shù)(相對(duì)于x)為2x,可以說2x的不確定積分是x^2。
在符號(hào)中 -

因此可相當(dāng)于 -

不確定積分并不是唯一的,因?yàn)閷?duì)于常數(shù)c的任何值,x^2 + c的導(dǎo)數(shù)也將是2x。
這用符號(hào)表示為 -

其中,c被稱為“任意常數(shù)”。
MATLAB提供了一個(gè)用于計(jì)算表達(dá)式積分的int命令。 為了得出一個(gè)函數(shù)的無(wú)限積分的表達(dá)式,它的寫法為 -
int(f);
例如,引用之前的例子 -
syms x
int(2*x)
MATLAB執(zhí)行上述語(yǔ)句將返回以下結(jié)果 -
ans =
x^2
示例1
在這個(gè)例子中,有一些常用表達(dá)式的積分。 創(chuàng)建腳本文件并在其中鍵入以下代碼 -
syms x n
int(sym(x^n))
f = 'sin(n*t)'
int(sym(f))
syms a t
int(a*cos(pi*t))
int(a^x)
MATLAB執(zhí)行上述語(yǔ)句將返回以下結(jié)果 -
ans =
piecewise([n == -1, log(x)], [n ~= -1, x^(n + 1)/(n + 1)])
f =
sin(n*t)
ans =
-cos(n*t)/n
ans =
(a*sin(pi*t))/pi
ans =
a^x/log(a)
示例2
創(chuàng)建腳本文件并在其中鍵入以下代碼 -
syms x n
int(cos(x))
int(exp(x))
int(log(x))
int(x^-1)
int(x^5*cos(5*x))
pretty(int(x^5*cos(5*x)))
int(x^-5)
int(sec(x)^2)
pretty(int(1 - 10*x + 9 * x^2))
int((3 + 5*x -6*x^2 - 7*x^3)/2*x^2)
pretty(int((3 + 5*x -6*x^2 - 7*x^3)/2*x^2))
請(qǐng)注意,
pretty函數(shù)返回表達(dá)式的更可讀格式。
MATLAB執(zhí)行上述語(yǔ)句將返回以下結(jié)果 -
ans =
sin(x)
ans =
exp(x)
ans =
x*(log(x) - 1)
ans =
log(x)
ans =
(24*cos(5*x))/3125 + (24*x*sin(5*x))/625 - (12*x^2*cos(5*x))/125 + (x^4*cos(5*x))/5 - (4*x^3*sin(5*x))/25 + (x^5*sin(5*x))/5
2 4
24 cos(5 x) 24 x sin(5 x) 12 x cos(5 x) x cos(5 x)
----------- + ------------- - -------------- + ----------- -
3125 625 125 5
3 5
4 x sin(5 x) x sin(5 x)
------------- + -----------
25 5
ans =
-1/(4*x^4)
ans =
tan(x)
2
x (3 x - 5 x + 1)
ans =
- (7*x^6)/12 - (3*x^5)/5 + (5*x^4)/8 + x^3/2
6 5 4 3
7 x 3 x 5 x x
- ---- - ---- + ---- + --
12 5 8 2
MATLAB執(zhí)行上述語(yǔ)句將返回以下結(jié)果 -
根據(jù)定義,定積分基本上是一個(gè)總和的極限。 我們使用定積分來(lái)查找曲線和x軸之間的面積以及兩條曲線之間的面積。定量積分也可用于其他情況,其中所需數(shù)量可以表示為總和的極限。
通過傳遞要計(jì)算積分的極限,int函數(shù)可用于定積分。
參考公式 -

它的寫法是 -
int(x, a, b)
例如,要計(jì)算的值是 -

因此,可以書寫為 -
int(x, 4, 9)
MATLAB執(zhí)行上述語(yǔ)句將返回以下結(jié)果 -
ans =
65/2
以下是以上示例的Octave寫法 -
pkg load symbolic
symbols
x = sym("x");
f = x;
c = [1, 0];
integral = polyint(c);
a = polyval(integral, 9) - polyval(integral, 4);
display('Area: '), disp(double(a));
可以使用Octave提供的quad()函數(shù)編寫另一個(gè)替代求解代碼,如下所示:
pkg load symbolic
symbols
f = inline("x");
[a, ierror, nfneval] = quad(f, 4, 9);
display('Area: '), disp(double(a));
示例1
下面來(lái)計(jì)算x軸和曲線y = x^3-2x + 5和縱坐標(biāo)x = 1和x = 2之間的面積。
所需面積由公式計(jì)算 -

創(chuàng)建腳本文件并鍵入以下代碼 -
f = x^3 - 2*x +5;
a = int(f, 1, 2)
display('Area: '), disp(double(a));
MATLAB執(zhí)行上述語(yǔ)句將返回以下結(jié)果 -
a =
23/4
Area:
5.7500
以下是上面示例的Octave寫法 -
pkg load symbolic
symbols
x = sym("x");
f = x^3 - 2*x +5;
c = [1, 0, -2, 5];
integral = polyint(c);
a = polyval(integral, 2) - polyval(integral, 1);
display('Area: '), disp(double(a));
可以使用Octave提供的quad()函數(shù)給出一個(gè)替代求解代碼,如下所示:
pkg load symbolic
symbols
x = sym("x");
f = inline("x^3 - 2*x +5");
[a, ierror, nfneval] = quad(f, 1, 2);
display('Area: '), disp(double(a));
MATLAB執(zhí)行上述語(yǔ)句將返回以下結(jié)果 -
Area:
5.7500
示例2
查找曲線下面積:f(x)= x^2 cos(x),對(duì)于-4≤x≤9。
創(chuàng)建一個(gè)腳本文件并寫下面的代碼 -
f = x^2*cos(x);
ezplot(f, [-4,9])
a = int(f, -4, 9)
disp('Area: '), disp(double(a));
MATLAB執(zhí)行上述語(yǔ)句將返回以下結(jié)果 -

同時(shí)也會(huì)輸出以下內(nèi)容 -
a =
8*cos(4) + 18*cos(9) + 14*sin(4) + 79*sin(9)
Area:
0.3326
以下是上面示例的Octave寫法 -
pkg load symbolic
symbols
x = sym("x");
f = inline("x^2*cos(x)");
ezplot(f, [-4,9])
print -deps graph.eps
[a, ierror, nfneval] = quad(f, -4, 9);
display('Area: '), disp(double(a));