Calculating Limits Using MATLAB

In advanced mathematics, we often encounter the problem of solving the limit, and MATLAB provides the solution to the limit.

Table of contents

1 Definition of limit

2 limit function

2.1 The limit tends to 0

2.2 When the limit tends to a certain value

2.3 Left limit and right limit

2.4 Simplification before limit function calculation

2.4 Use MATLAB to solve more complex limit problems


1 Definition of limit

"Limit" is a branch of mathematics - the basic concept of calculus. "Limit" in a broad sense means "infinitely close and never reachable". The "limit" in mathematics refers to: a certain variable in a certain function, in the process of becoming larger (or smaller) and forever changing, gradually approaches a certain value A and "never can In the process of coincidence to A" ("can never be equal to A, but equal to A' is enough to obtain high-precision calculation results), the change of this variable is artificially stipulated as "always approaching without stopping", which has a " The trend of being very close to point A constantly". The limit is a description of a "change state". The value A that this variable always approaches is called the "limit value" (of course, it can also be expressed by other symbols). (The definition in this paragraph comes from Definition of Baidu Encyclopedia Limit )

2 limit function

2.1 The limit tends to 0

The limit function is provided in MATLAB to solve the limit, and the most common case is that the limit tends to 0.

For example for solving:

y=\lim_{x \to 0}\frac{sinx}{x}

y=\lim_{x \to 0}\frac{tanx}{x}

The code looks like this:

syms x
y1=limit(sin(x)/x)
y2=limit(tan(x)/x)

The running results are as follows:

y1 =
    1
y2 = 
    1

2.2 When the limit tends to a certain value

The limit function in MATLAB can limit to any specific value. At this time, the calling method of the limit function is as follows: limit(y,x,a), where y represents the dependent variable, x represents the independent variable, and a represents that the limit tends to a specific value.

For example, the following formula finds the limit when the current period is close to infinity:

\small y=\frac{1}{x^2}

 The MATLAB code looks like this:

syms x
y=1/(x^2);
y=limit(y,x,inf)

The running results are as follows:

y =
    0

It should be noted that in MATLAB, inf means infinity, -inf means negative infinity, and 1/inf means infinitesimal.

When tending to other cases, such as calculating the limit of the formula shown below:

\small y=\lim_{x\rightarrow 3}\frac{x^2-5x+6}{x^2-7x+12}

 The MATLAB code looks like this:

syms x
y=(x^2-5*x+6)/(x^2-7*x+12);
limit(y,x,3)

The running results are as follows:

ans =
    -1

Verify it with:

\small \small y=\lim_{x\rightarrow 3}\frac{x^2-5x+6}{x^2-7x+12}=\lim_{x\rightarrow 3}=\frac{(x-3)(x-2)}{(x-3)(x-4)}=\lim_{x\rightarrow 3}=\frac{x-2}{x-4}=-1

 The same result as MATLAB can be obtained by verification. Therefore, MATLAB can calculate the limit tending to any value within the allowed range of the independent variable.

2.3 Left limit and right limit

In advanced mathematics, we often encounter situations where the left limit and the right limit are not the same. MATLAB also provides the value of calculating the respective left and right limits when the independent variable approaches a certain value. The way to calculate the left and right limits is as follows:

  • Left limit: limit(x,a,'left')
  • Right limit: limit(x,a,'right')

Among them, x represents the independent variable, a represents the specific value that the limit tends to, and left and right represent whether the limit tends to the left limit or the right limit.

In advanced mathematics, such as piecewise functions, there are usually cases where the left limit and right limit are different. Here is an example of a piecewise function:

\small y=\begin{cases} &2x-3 ,x\leq -3 \\ & x\ \ \ \ \ \ \ ,-3< x<4 \\ & x^2 \ \ \ \ \ \ ,x \geq 4 \end{cases}

 The MATLAB code looks like this:

syms x
y=piecewise(x<=-3,2*x-3,-3<x&x<4,x,x>=4,x^2);
lim_y1=limit(y,x,-3,'left')
lim_y2=limit(y,x,-3,'right')
lim_y3=limit(y,x,4,'left')
lim_y4=limit(y,x,4,'right')

The running results are as follows:

lim_y1 = 
    -9
lim_y2 =
    -3
lim_y3 =
    4
lim_y4 =
    16

It can be seen from the running results that in the piecewise function, when the symbolic function tends to the piecewise point a from different directions, the obtained results are also different.

2.4 Simplification before limit function calculation

When MATLAB is doing calculations, will it simplify the formula first? For example, simplify the following formula:

y=\lim_{x\rightarrow 0}\frac{x^2-9}{x^2-x+6}

The MATLAB code looks like this:

syms x
y=limit((x^2-9)/(x^2-x+6),x)

The running results are as follows:

y =
    -3/2
 

In the process of calculating the limit by ordinary people, it is generally simplified first, and then the operation of calculating the limit is performed on it, for example:

y=\lim_{x\rightarrow 0}\frac{x^2-9}{x^2-x+6}=\lim_{x\rightarrow 0}\frac{(x-3)^2}{(x-2)(x-3)}=\lim_{x\rightarrow 0}\frac{x-3}{x-2}=-\frac{3}{2}

 Does the computer also perform calculations in this order when performing calculations? Here we need to change the required formula to find out whether the computer is also in this order of calculation.

For example, calculate the limit of the following formula.

y=\lim_{ x \rightarrow 0}\frac{x^3-5x^2+6x}{x^2-4x}

In the face of this limit-seeking problem, usually the artificial calculation method is:

\small y=\lim_{ x \rightarrow 0}\frac{x^3-5x^2+6x}{x^2-4x} =\lim_{x\rightarrow 0}\frac{x(x-2)(x-3)}{x(x-4)} =\lim_{x\rightarrow 0}\frac{(x-2)(x-3)}{(x-4)} =-\frac{3}{2}

Use MATLAB to calculate it below:

syms x
y=(x^3-5*x^2+6*x)/(x^2-4*x);
limit(y)

The running results are as follows:

ans =
    -3/2

It cannot be found from the above results that when MATLAB calculates the limit, it first simplifies the formula, and then calculates the limit value.

2.4 Use MATLAB to solve more complex limit problems

MALTAB can be used to solve more complex limit-seeking problems, such as:

\small y=\lim_{x \rightarrow 0}\frac{tanx-x}{x^3}

For this question, if you use the artificial calculation method, you can use L'Hopital's law. Here is a brief description of the artificial calculation method process:

\small y=\lim_{x \rightarrow 0}\frac{tanx-x}{x^3}=\lim_{x\rightarrow 0}\frac{sec^2x-1}{3x^2}=\lim_{x \rightarrow 0}\frac{2secxtanx}{6x}=\frac{1}{3}\lim_{x\rightarrow 0}secx=\frac{1}{3}

 The code to solve it using MATLAB is as follows:

syms x
y=(tan(x)-x)/(x^3);
limit(y,x,0)

The result looks like this:

ans =
     1/3

In practical applications, if we do not only require the result but not the process, then we can choose to use MATLAB for calculation, which is more convenient.

Here are a few more complex examples:

\small y=\lim_{x \rightarrow 0}\frac{\sqrt{1+2sinx}-x-1}{xln(x+1)}

 The code for calculation using MATLAB is:

syms x
y=(sqrt(1+2*sin(x))-x-1)/(x*log(x+1));
limit(y,x,0)

The running results are as follows:

ans = 
    -1/2

(The artificial calculation method of the above formula will not be elaborated here).

Another example:

\small y=\lim_{x\rightarrow 0}(\frac{2}{x^2-1}-\frac{1}{x-1})

 Using MATLAB code to calculate:

syms x
y=(2/(x^2-1)-1/(x-1));
limit(y,x,0)

The running results are as follows:

ans =
     -1

MATLAB can also perform limit operations on symbolic expressions of multiple symbolic functions, for example, perform limit operations on the following formula:

\small y=\lim_{x \rightarrow a}\frac{sinx-sina}{x-a}

 The MATLAB code looks like this:

syms x a
y=(sin(x)-sin(a))/(x-a);
limit(y,x,a)

The running results are as follows:

ans =
    cos(a)

It can be seen from the results that the limit function of MATLAB can perform limit operations on expressions of multi-symbol variables.

Guess you like

Origin blog.csdn.net/qq_54186956/article/details/127588580