Introduction to Symbolic Math Toolbox in Matlab

1.What Is the Symbolic Math Toolbox?

The Symbolic Math Toolbox is a functionality in Matlab for operations on symbolic objects. It introduces a special data type symbolic objects;

This data type includes symbolic numbers, symbolic variables, symbolic expressions, and symbolic functions, as well as symbolic matrices and symbolic arrays composed of the above variables, which are also referred to as symbolic types;

The Symbolic Math Toolbox provides functionalities for solving, plotting, and manipulating symbolic math equations, which are referred to as symbolic computations.

2.Why Use Symbolic Computation?

Firstly, the conventional numeric data types (floating-point) in Matlab typically use decimal approximations for storage and computation. For example, 10/3=3.3333, due to hardware storage limitations, the result 3.3333 is not the true result of 3 and 1/3, but in general applications, this is not a significant issue;

When precision in calculations is particularly important, this issue becomes significant;

Thus, symbolic computation was born. It stores variables in a symbolic manner. For example, the above 10/3 uses symbolic computation to express the result as 10/3, which is indeed in fractional form;

3.Creating Symbolic Objects (Variables)

Symbolic variables can be directly used after declaration (creation) without output results, but they are stored in the workspace;

To create a symbolic variable, use the functions sym and syms

Example:

sym(‘x’) % Syntax 1

syms x % Syntax 2

syms x y z % Create multiple symbolic variables

sym(‘x’,[1 5]) % Create symbolic variables x1/x2/x3/x4/x5

4.Precision Differences Between Symbolic and Numeric Types

Example:

1/6 % Double-precision floating-point 1/6, expressed in Matlab as 0.1667

x=sym(1/6) % Create a symbolic variable, expressed in fractional form as 1/6

sin(pi) % Double-precision floating-point pi value calculation sin value, with rounding error 1.2246e-16

sin(sym(pi)) % Compute the sin value of the symbolic object pi, fully expressed as 0

5.Symbolic Expressions

Example:

syms x y z

f=2*x+1 % Symbolic expression

g=x*y+z

6.Symbolic Functions

The usage of symbolic functions is the same as that of conventional functions, with the difference being the data types handled. When performing operations with symbolic objects, one must first declare the symbolic objects and can express results in a formal manner.

Example:

syms x

f(x)=2*x+1 % Symbolic function

f(1) % Call the symbolic function, resulting in a symbolic object3

syms f(x,y) % Directly create (declare) a function without a function expression

f(x,y) % Call

f(1,2) % Result of the operationf(1,2)

7.Symbolic Matrices

The usage of symbolic matrices is the same as that of conventional matrices, with the difference being the data types handled. When performing operations with symbolic objects, one must first declare the symbolic objects and can express results in a formal manner.

Example:

syms a b c d % Declare symbolic variables

A=[a b;c d] % Symbolic matrix

B=[a 1;c 3]

sum(A) % Symbolic matrix operation, same as conventional matrix algorithms

sum(B)

sym(‘x’,[2 2]) % Create a 2 by 2 matrix, automatically adding subscripts

sym(‘x%d%d’,[2 2]) % Return result[x11, x12; x21, x22]

sym(‘x%d2018%d’,[2 2]) %2 Add numbers in between two subscripts

More Related Content

  • Getting Started with Matlab 47: How to Plot DateTime Data on the X-Axis

  • Matlab 40: Relationship Operations with DateTime Data: Comparing Values, Time Order, and Checking Between Two Times

  • Concise Programming Example: Solving a Univariate Polynomial Equation in Matlab

  • Matlab Q&A 17: In the new century and new stage, many students still use newff and sim for learning neural networks, but actually…

  • Getting Started 15: Discussing What Inf and NaN Are in Matlab, and How to Create, Judge, and Operate?

  • Series 24 KNN Nearest Neighbor Algorithm and Matlab Programming

  • [New Release] Series 37 Matlab AppDesigner Interface Design Programming Case Document, Strongly Recommended for Scientific Research and Software Copyright Writing

  • Series 47 Matlab and Genetic Algorithms

  • Series 31 Matlab Plotting (Most Comprehensive)

  • Series 43 Matlab Neural Networks Fitting/Classification

  • Series 49 Matlab and Simulated Annealing Algorithms

  • Series 23 Matlab Fitting Programming: Data Fitting, Function Fitting, Curve and Surface Fitting

  • Series 22 Matlab Optimization

  • 45 Matlab Deep Learning Convolutional Neural Networks

  • Matlab Exercise 2.2: Concepts and Applications of Matrix Indexing

  • Matlab Exercise 1.7: Function Syntax and Function Files

End

Leave a Comment