MATLAB 集成(Integration)

集成處理兩種本質(zhì)上不同的問題。

  • 在第一種類型中,給出了函數(shù)的導(dǎo)數(shù),我們想找到函數(shù)。因此,我們從根本上扭轉(zhuǎn)了分化的過程。這種反向過程稱為反微分,或者找到原始函數(shù),或者找到indefinite integral。

  • 第二類問題涉及相加大量非常小的數(shù)量,然后隨著數(shù)量的大小接近零而取一個極限,而項的數(shù)量趨于無窮大。此過程導(dǎo)致的定義definite integral

定積分用于查找面積,體積,重心,慣性矩,力完成的功以及許多其他應(yīng)用。

使用MATLAB查找不定積分

根據(jù)定義,如果函數(shù)的導(dǎo)數(shù)f(x)是f'(x),那么我們說f'(x)相對于x的不定積分是f(x)。例如,由于x 2的導(dǎo)數(shù)(相對于x)為2x,因此可以說2x的不定積分為x 2。

在符號中-

f'(x2) = 2x, 所以,

∫ 2xdx = x2.

不定積分不是唯一的,因為對于常數(shù)c的任何值,x 2 + c的導(dǎo)數(shù)也將是2x。

這用符號表示為-

∫ 2xdx = x2 + c。

其中,c被稱為“任意常數(shù)”。

MATLAB提供了int用于計算表達式積分的命令。為了導(dǎo)出一個函數(shù)的不定積分的表達式,我們寫:

int(f);

例如,從我們之前的示例中-

syms x 
int(2*x)

MATLAB執(zhí)行上述語句并返回以下結(jié)果-

ans =
   x^2

實例1

在此示例中,讓我們找到一些常用表達式的積分。創(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)

運行文件時,它顯示以下結(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))

請注意,pretty函數(shù)以更易讀的格式返回表達式。

運行文件時,它顯示以下結(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查找定積分

根據(jù)定義,定積分基本上是總和的極限。我們使用定積分來查找面積,例如曲線和x軸之間的面積以及兩條曲線之間的面積。在其他情況下也可以使用定積分,在這種情況下,所需數(shù)量可以表示為總和的極限。

int通過傳遞要計算積分的極限,該函數(shù)可用于確定積分。

計算

定積分

我們寫,

int(x, a, b)

例如,要計算值,實例我們寫:

int(x, 4, 9)

MATLAB執(zhí)行上述語句并返回以下結(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執(zhí)行代碼并返回以下結(jié)果-

Area: 

   32.500

可以使用quad()Octave提供的功能給出代替解決方案,如下所示:

pkg load symbolic
symbols

f = inline("x");
[a, ierror, nfneval] = quad(f, 4, 9);

display('Area: '), disp(double(a));

Octave執(zhí)行代碼并返回以下結(jié)果-

Area: 
   32.500

實例1

讓我們計算在x軸和曲線y = x 3 -2x + 5以及縱坐標x = 1和x = 2之間所包圍的面積。

所需面積由下式給出:

面積計算

創(chuàng)建一個腳本文件并輸入以下代碼-

f = x^3 - 2*x +5;
a = int(f, 1, 2)
display('Area: '), disp(double(a));

運行文件時,它顯示以下結(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執(zhí)行代碼并返回以下結(jié)果-

Area: 

   5.7500

可以使用quad()Octave提供的功能給出代替解決方案,如下所示:

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));

Octave執(zhí)行代碼并返回以下結(jié)果-

Area: 
   5.7500

實例2

找出曲線下的面積:   f(x)= x 2 cos(x)表示?4≤x≤9。

創(chuàng)建一個腳本文件并編寫以下代碼-

f = x^2*cos(x);
ezplot(f, [-4,9])
a = int(f, -4, 9)
disp('Area: '), disp(double(a));

運行文件時,MATLAB繪制圖形-

定積分

輸出如下-

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));
丰满人妻一级特黄a大片,午夜无码免费福利一级,欧美亚洲精品在线,国产婷婷成人久久Av免费高清