The basis of the symbolic operation of MATLAB

Source: Internet
Author: User

Author: Wang Flight, School of Transportation Engineering, Changsha University of Technology


In mathematical operations, if the result of an operation is a numeric value, it can be called a numerical operation, and if the result of the operation is an expression, which is called the symbolic operation in MATLAB, the symbolic calculation is the operation and processing of an unassigned symbolic object (which can be a constant, a variable, an expression). Matlab has a symbolic math toolbox (Symbolicmath Toolbox), which combines symbolic operations into the numerical computing environment of MATLAB. The Symbolic mathematical tool box is based on the Maple software.

(a) Symbolic variables establish symbolic variables and symbolic constants

There are two methods for establishing symbolic variables, applying sym and syms functions, usually using SYM to establish symbolic expressions, and applying syms to define multiple symbolic variables simultaneously.

(1) function : sym

function: used to create a single symbol volume

grammatical form : sym (' expression or variable ')

Example :

A = Sym (' a ');     % defines the symbolic variable A, the same as B = sym (' b ') c = sym (' c ') d = sym (' d ')  % to this point defines 4 symbolic variables w = 10;x = 5;y = -8;z = 11; A = [A,b;c,d]% establishes the symbol matrix AB = [W,x;y,z]% establishes a numerical matrix BC = det (a); % computes the determinant of the symbol matrix A d = det (B); % establish determinant of the value matrix B
The following results can be obtained:


It is not difficult to see from the above results that the results are presented in symbolic operations in the form of expressions, whereas in numerical operations the results are expressed numerically.

(2) Function: Syms

function : Define multiple symbol variables

syntax : syms Var1 Var2 ... Varn

Description : The function defines the symbolic variable var1,var2,......,varn and so on. When you define a symbolic variable in this format, you do not need to add a character break (') to the variable name, separate the variable with a space instead of a comma, and separate it with a space.

Example 2: Applying the Syms function to define a symbolic variable

Syms x y% also defines x, y as the symbol variable a = [sin (x) sin (y); cos (x) cos (y)]</span>
(ii) basic symbolic Operations

1 Basic Symbolic arithmetic functions

In MATLAB, there are many functions that apply to symbolic operations, and commonly used functions are shown in the following table:

Name of function

Function

Examples of usage

sym

string or value-to-symbol toggle

sym (' a+b ')

Expand

Expand

Syms x

s = ( -7*x^2-8*y^2) * (-x^2+3*y^2);

Expand (s)

Collect (S,X)

Factor (ANS)

g = simple (ans)

Collect

Merging similar terms

Factor

Factorization

Simplify

Simple

Simplification

Sym2poly (S)

Conversion S is a polynomial coefficient vector

Syms x;f= ' 2*x^2+3*x-5 ';

n = sym2poly (f)

Poly2sym (N)

Poly2sym (c)

Convert polynomial coefficients vector c to symbolic polynomial


2 Symbolic expression operations

(1) Arithmetic of symbolic expressions

Syms x y z; % definition x, y, Z for symbol variable f1 = 2*X+X^2*X-5*X+X^3F2 = 2*x/(5*x) F3 = (x+y) * (x-y) </span>

(2) factorization and polynomial expansion

function 1: Factor

function : decomposition-dependent

syntax : Factor (s)

Description : S is a symbolic expression or symbol matrix


function 2: Collect

function : Merge similar terms

syntax : Collect (s)

Collect (S,X)

Description : The S is a symbolic expression or a symbol matrix for the same-item merge with the symbol variable x.


Example: Factoring an expression

f = sym (' x-1 '/(x^2+2*x-3) '); % input expression F = factor (f)  % factorization of symbolic expression F </span>



(3) Expression simplification

MATLAB provides a simple function for symbolic expression of simplify.

function : Simplify

function : Simplify the expression

Syntax : Simplfy (S)

F=cos (x) ^2+sin (x) ^2simplify (f)


Note:simplify and simple are the two simplified functions provided by the MATLAB Symbolic Math tool box, with the following differences:
the invocation format for simplify is: simplify (s), and the expression S is simplified.
Simple is to seek the simplest form of the symbolic expression s by simplifying the expression by experimenting with many different methods, including simplify.
The method is called:
[R,how]=simple (S); R is a simplified form of return, how is a method used in the simplification process. How is available in the following ways:
(1) Simplify function to simplify the expression;
(2) Radsimp function to simplify the expression containing radical;
(3) The Combine function merges the items appearing in the expression in the form of sum, product, power operation, etc.
(4) Collet merger similar terms
(5) factorization of factor function
(6) Convert function to complete the conversion of the form of an expression


Reference documents

[1] Liu Gahai, Shang and other editors. MATLAB visualization scientific calculation [M]: Zhejiang: Zhejiang University Press, 2014.6

[2] Shidingyu, Chenyangquan, editor-in-chief. MATLAB solution for higher applied mathematical problems [M]: Second edition. Beijing: Tsinghua University Press, 2015.6

The basis of the symbolic operation of MATLAB

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.