English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

MATLAB Integration

Integration handles two fundamentally different problems.

  • In the first type, the derivative of the function is given, and we want to find the function. Therefore, we fundamentally reverse the process of differentiation. This reverse process is called anti-differentiation, or finding the original function, or findingindefinite integral.

  • The second type of problem involves adding a large number of very small quantities, then taking a limit as the size of the quantity approaches zero, and the number of terms tends to infinity. This process leads to the definitiondefinite integral.

Definite integral is used to find area, volume, center of gravity, moment of inertia, work done by force, and many other applications.

Using MATLAB to find indefinite integral

According to definition, if the derivative of the function f(x) is f'(x), then we say that the indefinite integral of f'(x) with respect to x is f(x). For example, since x 2the derivative (with respect to x) of2x, therefore, it can be said that2the indefinite integral of x is x 2.

in the symbol-

f'(x2) = 2x, also,

∫ 2xdx = x2.

不定积分不是唯一的,因为对于常数c的任何值,x 2 + c的导数也将是2x。

这用符号表示为-

∫ 2xdx = x2 + c.

其中,c被称为“任意常数”。

MATLAB提供了int用于计算表达式积分的命令。为了导出一个函数的不定积分的表达式,我们写:

int(f);

例如,从我们之前的示例中-

syms x 
int(2*x)

MATLAB执行上述语句并返回以下结果-

ans =
   x^2

Beispiel1

在此示例中,让我们找到一些常用表达式的积分。创建一个脚本文件并在其中键入以下代码-

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)

Wenn Sie die Datei ausführen, zeigt sie das folgende Ergebnis an-

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)

Beispiel2

创建一个脚本文件并在其中键入以下代码-

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函数以更易读的格式返回表达式。

Wenn Sie die Datei ausführen, zeigt sie das folgende Ergebnis an-

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查找定积分

根据定义,定积分基本上是总和的极限。我们使用定积分来查找面积,例如曲线和x轴之间的面积以及两条曲线之间的面积。在其他情况下也可以使用定积分,在这种情况下,所需数量可以表示为总和的极限。

int通过传递要计算积分的极限,该函数可用于确定积分。

计算

我们写,

int(x, a, b)

例如,要计算值,我们写:

int(x, 4, 9)

MATLAB执行上述语句并返回以下结果-

ans =
   65/2

Hier ist das Octaveäquivalent der obigen Berechnung-

pkg load symbolic
symbols
x = sym("x");
f = x;
c = [1, 0];
integral = polyint(c);
a = polyval(integral, 9) - polyval(integral, 4);
display('Fläche: '), disp(double(a));

Octave führt den Code aus und gibt das folgende Ergebnis zurück-

Fläche: 
   32.500

Man kann die Funktion quad() von Octave verwenden, um eine Alternative zu bieten, wie folgt:

pkg load symbolic
symbols
f = inline("x");
[a, ierror, nfneval] = quad(f, 4, 9);
display('Fläche: '), disp(double(a));

Octave führt den Code aus und gibt das folgende Ergebnis zurück-

Fläche: 
   32.500

Beispiel1

让我们计算在x轴和曲线y = x 3 -2x + 5以及纵坐标x = 1和x = 2由其包围的面积。

Die erforderliche Fläche gibt die folgende Formel an:

Erstellen Sie eine Skriptdatei und geben Sie den folgenden Code ein-

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

Wenn Sie die Datei ausführen, zeigt sie das folgende Ergebnis an-

a =
23/4
Fläche: 
   5.7500

Hier ist das Octaveäquivalent der obigen Berechnung-

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('Fläche: '), disp(double(a));

Octave führt den Code aus und gibt das folgende Ergebnis zurück-

Fläche: 
   5.7500

Man kann die Funktion quad() von Octave verwenden, um eine Alternative zu bieten, wie folgt:

pkg load symbolic
symbols
x = sym("x");
f = inline("x^3 - 2*x +5");
[a, ierror, nfneval] = quad(f, 1, 2);
display('Fläche: '), disp(double(a));

Octave führt den Code aus und gibt das folgende Ergebnis zurück-

Fläche: 
   5.7500

Beispiel2

Finden Sie die Fläche unter der Kurve: f(x)= x 2 cos(x) bedeutet −4≤x≤9.

Erstellen Sie eine Skriptdatei und schreiben Sie den folgenden Code-

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

Wenn Sie die Datei ausführen, zeichnet MATLAB ein Diagramm-

Die Ausgabe ist wie folgt-

a = 
8*cos(4) + 18*cos(9) + 14*sin(4) + 79*sin(9)
 
Fläche: 
   0.3326

Hier ist das Octaveäquivalent der obigen Berechnung-

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('Fläche: '), disp(double(a));