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

MATLAB Calculus

MATLAB provides various methods to solve differential and integral problems, solve differential equations of any degree, and calculate limits. Most importantly, you can easily solve the graph of complex functions and check the maximum, minimum, and other points on the graph by solving the original function and its derivatives.

This chapter will discuss the issues of calculus. In this chapter, we will discuss the concept of pre-calculation, that is, calculating the limit of a function and verifying the properties of the limit.

In the next chapter on differentiation, we will calculate the derivative of an expression and find the local maximum and minimum values of the graph. We will also discuss solving differential equations.

Finally, in theIntegrationIn this chapter, we will discuss integral calculus.

to calculate limits

MATLAB provideslimitThe function used to calculate limits.limitThe function takes the expression as a parameter in its most basic form and finds the limit of the expression when the independent variable becomes zero.

For example, let's calculate the limit of the function f(x) = (x 3 + 5)/(x 4 + 7)), because x approaches zero.

syms x
limit((x^3 + 5)/(x^4 + 7))

MATLAB will execute the above statements and return the following results-

ans =
   5/7

The limit function belongs to the field of symbolic computation. You need to usesymsfunction to tell MATLAB which symbolic variables you are using. You can also calculate the limit of a function because the variable approaches some number other than zero. To calculate lim x-> a((f(x))), we use the limit command with parameters. The first is the expression, and the second isxapproximate numerical value, which isa.

For example, let's calculate the limit of the function f(x) = (x-3)/(x-1), because x approaches1.

limit((x - 3)/(x-1,1)

MATLAB will execute the above statements and return the following results-

ans =
   NaN

Let's take another example

limit(x^2 + 5, 3)

MATLAB will execute the above statements and return the following results-

ans =
   14

To calculate the limit using Octave

Below is the use ofsymbolicThe above example is for the Octave version of the package, please try to execute and compare the results-

pkg load symbolic
symbols
x = sym("x");
subs((x^3+5)/(x^4+7), x, 0)

Octave will execute the above statements and return the following results-

ans =
   0.7142857142857142857

Verification of the basic properties of limits

The algebraic limit theorem provides some basic properties of limits. These are as follows-

Let's look at two functions-

  • f(x) = (3x + 5)/(x-3)

  • g(x) = x 2 +1.

Let's calculate the limits of the two functions as x approaches5The function limits, and use these two functions and MATLAB to verify the basic properties of limits.

Example

Create a script file and enter the following code-

syms x
f = (3*x + 5)/(x-3]);
g = x^2 + 1;
l1 = limit(f, 4)
l2 = limit(g, 4)
lAdd = limit(f + g, 4)
lSub = limit(f - g, 4)
lMult = limit(f*g, 4)
lDiv = limit(f/g, 4)

When the file is run, it displays-

l1 =
   17
  
l2 =
   17
  
lAdd =
   34
 
lSub =
   0
  
lMult =
   289
  
lDiv =
   1

To verify the basic properties of limits using Octave

Below is the use ofsymbolicThe above example is for the Octave version of the package, please try to execute and compare the results-

pkg load symbolic
symbols
x = sym("x");
f = (3*x + 5)/(x-3]);
g = x^2 + 1;
l1 = subs(f, x, 4)
l2 = subs(g, x, 4)
lAdd = subs(f+g, x, 4)
lSub = subs(f-g, x, 4)
lMult = subs(f*g, x, 4)
lDiv = subs(f/g, x, 4)

Octave will execute the above statements and return the following results-

l1 =
   17.0
l2 =
   17.0
lAdd =
   34.0
lSub =
   0.0
lMult =
   289.0
lDiv =
   1.0

Left and Right Limits

When a function has discontinuity for a specific value of the variable, there is no limit at this time. In other words, the limit of the function f(x) at x = a has discontinuity because when x approaches x from the left, the limit value is not equal to the value of x approaching x from the right.

This leads to the concept of left-hand and right-hand limits. The left-hand limit is defined as the limit starting from the left side of x, that is, x-> a, that is, x approaches a when x <a, the right-hand limit is defined as starting from the right x-> a's limit, that is, for x> a, x approaches a. When the left-hand limit and the right-hand limit are not equal, the limit does not exist.

Let's look at a function-

f(x) = (x - 3)/|x - 3|

We will show lim x-> 3 f(x) does not exist. MATLAB helps us establish this fact in two ways-

  • By plotting the function graph and showing discontinuities.

  • By calculating the limits and showing that they are different.

The left-hand and right-hand limits are calculated by passing the string 'left' and 'right' as the last argument to the limit command.

Example

Create a script file and enter the following code-

f = (x - 3)/abs(x-3]);
ezplot(f,[-1,5])
l = limit(f,x,3left)
l = limit(f,x,3right)

When running the file, MATLAB draws the following diagram

Display output after running the file-

l = limit(f,x,
   -1
  
r = limit(f,x,
   1