Mathematical calculation of MATLAB symbols

Source: Internet
Author: User
Tags cos diff sin

The symbolic computation holds the accurate data, consumes the storage space, the operation speed is slow, but the result precision is high, the numerical computation is calculates with the certain precision, the calculation result has the error, but the operation speed is fast. The difference between the two is that the expression of the numerical calculation, the matrix variable is not allowed to have undefined free variables, and the symbolic calculation can contain undefined symbol variables.

I. Symbolic objects and symbolic expressions

Close All;clear ALL;CLC;
The creation of the percent symbol object
syms x y z;% symbolic variable
a=sym (2/3, ' f ');% symbol constant
b=2*y^2+y-1;% symbol expression
c=[1 2+y 2;2+z 1 1+y];% symbol matrix
% Operators and Functions
syms a b c d e F g H;
A2=[a B;c d];
B2=[e f;g h];
c2=a2*b2;% symbolic computation and numerical computation are almost identical to the percent of the
category recognition function
syms x;
A3=class (x);% returns the category of the symbol object
b3=isa (x, ' sym ');% returns 1 or 0
whos x;% lists the variable information about the variables
syms a b C;
a4=3*a+b-c;
Symvar (A4);% find all the symbol variables in the expression
Symvar (a4,2);% find expression in distance x the nearest 2 symbol variable percent
symbol precision calculation
syms x;
a5=2*x^2+3*x-4;
B5=solve (A5);
D5=VPA (b5,6);% for approximate solution with 6-bit accuracy

Second, the operation of symbolic expressions

Close All;clear ALL;CLC;
The display of the percent sign expression
syms x;
a=x^2+2/x+1;
Pretty (a);
The combination of the percent sign expression
syms x y;
A2=2*x+y+x*cos (y);
Collect (A2);
The expansion of the percent-sign expression
syms x y;
A3=exp ((x+y) ^2);
Expand (A3);
The nested syms x y of the percent sign expression
;
A4=[x^2+x;y^3-2*y];
Horner (A4);
Percent-of-sign expression decomposition
syms x y;
a5=2*x^2-7*x*y-22*y^2-5*x+35*y-3;
Factor (A5);
The expression of percent-percent symbol is simplified
syms x;
a6= (x^3-1)/(x-1);
Simplify (A6);

Iii. Substitution of symbolic expressions

Close All;clear ALL;CLC;
The substitution of the percent sign expression
syms x y;
a=x^2+x*y+y^2;
x=2;
Subs (a);% replaces the default variable in the symbol expression with a variable in the workspace
subs (A, ' t ');% replaces the default variable in the symbol expression with a new variable
subs (a,{' x ', ' Y '},{3,4}); Replace the variable specified in the symbol expression with a new variable

Iv. operation of Symbolic functions

Close All;clear ALL;CLC;
The compound function
syms x y;
a=x+x^-1;
B=sin (x);
c=1+y^2;
Compose (A, b);% returns the compound function A (y)
compose (a,c, ' x ', ' t '), and the% returns the compound function A (c (t)) of the argument T is
syms x y;
a2=1/(sin (x) +cos (x));
b2=x^2+2*x*y+y^2;
A22=finverse (A2);% returns A2 's inverse function
b22=finverse (b2,y);% returns the b2 inverse of the argument y, which satisfies B22 (B2 (y)) =y

Five, Symbolic calculus

Close All;clear ALL;CLC;
Percent Sign differential
syms x y z;
A=exp (X*sin (y)) +log (z);
diff (A,z),% to Z differential
diff (a,x,2),% to Z for second order differential
b=[x^2+y^2;y*z];
Jacobian (b,[x y]);%b is the column vector, [x y] is the line vector that specifies the transform, the percent of the
symbol integral
syms x y;
a2=x*y+ (x*y) ^-1;
Int (a2,y),% to Y indefinite integral
int (a2,y,1,2),% to Y to set integral percent
sign series sum
syms x N;
a3=x^2;
B3=symsum (a3,x,0,n-1);% of x 0 to N-1 Limited and Percent
Taylor series
syms x y;
A4=sin (x) +1/cos (y);
Taylor (A4,x, ' order ', 4)%n-1 Taylor
(a4,x, ' Expansionpoint ', 1, ' Order ', 4)%n-1-order Taylor series expands at Expansionpoint

Six, Symbolic integration transformation

The percent Fourier transform and its inverse transform
syms t W;
A=sin (t) *cos (t);
B=fourier (a,t,w);% Fourier transform
c=ifourier (b,w,t);% Fourier inverse transform
simplify (c)
; The percent Laplace transform and its inverse transform
syms s t;
Syms a positive;
A2=exp (2*t) +5*dirac (a-t);
B2=laplace (a2,t,s);% Laplace transform
ilaplace (b2,s,t);% laplace inverse transform percent
Z transform and its inverse transform
syms a b n W;
A3=sin (a*n) +cos (b*n);
B3=ztrans (A3);%z transform
C3=ztrans (a3,a,w);% specifies the independent variable, w instead of complex frequency Z
iztrans (c3,w,n);%z Inverse transformation

Seven, symbolic algebraic equations and differential equation solving

Close All;clear ALL;CLC;
Syms x a b C for the solution of the percent-sign algebraic equation;
A1=a*x^2+b*x+c;
Solve (A1);% solution Equation
solve (a1,a);% specified variable, solution equation
syms x y;
a11= ' x^2+y^2=25 ';
b11= ' x*y==12 ';
[X,y]=solve (A11,B11);% simultaneous equation solution
syms x y a B;
A12= ' x^2+y^2==a^2 ';
B12= ' x*y==b ';
S=solve (a12,b12,x,y);% specifies a plurality of independent variables, the solution is the matrix structure
s.x;
The solution Syms x for the differential equation of percent sign
;
A2= ' a*dx+b*x=0 ';
Dsolve (A2);
Dsolve (A2, ' x (0) =1 ');
Dsolve (A2, ' x (0) =1 ', ' m ');
Syms x y;
A22= ' dx-3*x+2*y=0 ';
B22= ' dy-2*x+y=0 ';
[X,y]=dsolve (A22,B22);
[X,y]=dsolve (A22,b22, ' x (0) =1 ', ' Y (0) =1 ');

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.