Getting started with matlab----symbolic arithmetic

Source: Internet
Author: User

In addition to the normal numerical calculation, MATLAB can also perform symbolic operations. The following are some aspects of MATLAB's symbolic operations.
1. Creation of symbolic expressions and symbol matrices
2. Basic Symbolic arithmetic
3. Symbolic calculus
4. The solution of symbolic algebraic equations- -symbolic expressions and creation of symbolic matrices

1. Creation of symbolic expressions
The creation of symbolic expressions in MATLAB is divided into 3 ways:
(1) Create directly from a string
(2) The SYM function or the syms command declares the symbolic variable before creating

(1) Create directly by string method

>> f= ' x^2+6x+5 '

f =

x^2+6x+5

F is called a symbolic variable, and ' x^2+6x+5 ' is called a symbolic expression. A symbolic expression can be an expression or a symbolic equation.

>> f= ' 6x^2+5x=1 '

f =

6x^2+5x=1

(2) Create by sym function or Syms command
When using the Syms command, multiple variables must be separated by spaces and not by ",".

>> x=sym (' x ')

x =

x
>> f=x^2+6*x+5

f =

x^2 + 6*x + 5
>> syms a b x
>&G T F=a*x+b

f =

B + a*x

2. Creation of symbolic matrices
Identical to the creation of the symbolic expression, which can be created by means of a string and the sym,syms command.
(1) Create directly by string method

>> a=[' [A, b] '; ' [x, Y] '

a = [A,

b]
[x, Y]

(2) Create with sym,syms

>> b=sym (' [5*a,k;l y] ')

b =

[5*a, K]
[   l, y]
>> syms x y
>> [x y;y x]

ans =

[x, Y]
[Y, X]

3. Transformation of symbolic matrix and numerical matrix
Numerical matrix-"symbol matrix with B=sym (a), a as a numerical matrix, and B as the converted symbol matrix

>> num=[0.25,3;0.333,1.5]

num =

    0.2500    3.0000
    0.3330    1.5000

>> sym (num)

ans =

[   3]
[333/1000, 3/2]
two. Basic Symbolic arithmetic

The symbolic operation in MATLAB has a special symbolic arithmetic function.
Symadd (A, b) ————— – Addition of symbol matrices
Symsub (A, b) ————— – Subtraction of symbol matrices
Symmul (A, b) ————— – Multiplication of symbol matrices
Symdiv (A, b) ————— – Dividing the symbol matrix
Symop (A, b) ————— – integrated operation of symbolic matrices three. Symbolic calculus operation

The symbolic calculus operation in MATLAB relies mainly on the diff () and int () functions
The diff (F[,v][,n]) function makes a differential operation on the F sign expression, and if V is not missing, the differential to the V variable is performed, and if N is absent, the N-differential operation of the V variable of the F-expression.
The int (f[,v][,a][,b]) function integrals the F-symbol expression, and if V is not missing, indefinite integrals are made to the V variable, and if A and B are not missing, then the V variable of f is set to the integral on A to B.

>> f= ' 2*x^3+2 ';
>> diff (f)

ans =

6*x^2

>> diff (F, ' X ', 2)

ans =

12*x

>> int (f, ' X ')

ans =

(x* (x^3 + 4))/2

>> int (f, ' X ', 1,5)

ans =

320

Four. Solving of symbolic algebraic equations
In Matlab, solve () is used to solve the symbolic algebraic equations.
Solve (f) ————— – Solving the unknowns in the default symbolic algebraic equations
Solve (F1,f2 ...) ———-Algebraic equations

>> f= ' x^2+5*x+6=0 ';
>> solve (f)

ans =

 -3
 -2
>>  f1= ' 2*x+y-z=8 ';
>> f2= ' 3*y=6 ';
>> f3= ' 6*z=12 ';
>> [X,y,z]=solve (F1,F2,F3)

x =

4


y =

2


z =

2

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.