Matlab基础之符号表达式

前言:

为了计算更方面


一、表达式化简


1化简:

syms x y;%定义符号变量
f=x^2*y+x*y-x^2-2*x;
f(x)=collect(f) %合并同类项
g=-1/4*x*exp(-2*x)+3/16*exp(-2*x);
g(x)=collect(g,exp(-2*x))
h(x)=expand(f(x)*g(x))%相乘展开升幂排列
q(x)=factor(x^2-y^2)%
p(x)=simplify(x^2-y^2)%系统尽可能的去化简
>>Untitled
f(x) =
(y - 1)*x^2 + (y - 2)*x

g(x) =
(3/16 - x/4)*exp(-2*x)
 
h(x) =
(5*x^2*exp(-2*x))/16 - (3*x*exp(-2*x))/8 + (x^3*exp(-2*x))/4 + (3*x*y*exp(-2*x))/16 
- (x^2*y*exp(-2*x))/16 - (x^3*y*exp(-2*x))/4

q(x) =[ x - y, x + y]

p(x) = x^2 - y^2
2.符号求极限

limit    Limit of an expression.
    limit(F,x,a) takes the limit of the symbolic expression F as x -> a. %指定变量求极限
    limit(F,a) uses symvar(F) as the independent variable.
    limit(F) uses a = 0 as the limit point.
    limit(F,x,a,'right') or limit(F,x,a,'left') specify the direction    %分段函数左右极限
    of a one-sided limit.
 
    Examples:
      syms x a t h;
 
      limit(sin(x)/x)                 returns   1
      limit((x-2)/(x^2-4),2)          returns   1/4
      limit((1+2*t/x)^(3*x),x,inf)    returns   exp(6*t)
      limit(1/x,x,0,'right')          returns   inf
      limit(1/x,x,0,'left')           returns   -inf
      limit((sin(x+h)-sin(x))/h,h,0)  returns   cos(x)
      v = [(1 + a/x)^x, exp(-x)];
      limit(v,x,inf,'left')           returns   [exp(a),  0]
3符号微分

 diff(S) differentiates a symbolic expression S with respect to its
    free variable as determined by SYMVAR.
    diff(S,'v') or diff(S,sym('v')) differentiates S with respect to v.
    diff(S,n), for a positive integer n, differentiates S n times. %求n次微分
    diff(S,'v',n) and diff(S,n,'v') are also acceptable.           %对指定变量求n次微分
                                             
 
    Examples;
       syms x t
       diff(sin(x^2)) is 2*x*cos(x^2)
%%%%%%%%%%%%
syms x y;
f=sin(x^2+y-1);
f1=diff(f)
f2=diff(f,x)
f3=diff(f,y)
f4=diff(f,x,2)
>> Untitled 
f1 =2*x*cos(x^2 + y - 1)
f2 =2*x*cos(x^2 + y - 1) 
f3 =cos(x^2 + y - 1)
f4 =2*cos(x^2 + y - 1) - 4*x^2*sin(x^2 + y - 1)
 

4.符号积分

nt    Integrate
    int(S) is the indefinite integral of S with respect to its symbolic variable as defined by SYMVAR. S is a SYM (matrix or scalar).
      If S is a constant, the integral is with respect to 'x'. %默认求积分
 
    int(S,v) is the indefinite integral of S with respect to v. v is a scalar SYM.  %对符号V求积分
 
    int(S,a,b) is the definite integral of S with respect to its
      symbolic variable from a to b. a and b are each double or
      symbolic scalars. The integration interval can also be specified
      using a row or a column vector with two elements, i.e., valid
      calls are also int(S,[a,b]) or int(S,[a b]) and int(S,[a;b]).
 
    int(S,v,a,b) is the definite integral of S with respect to v from a to b. The integration interval can also be specified
      using a row or a column vector with two elements, i.e., valid  calls are also int(S,v,[a,b]) or int(S,v,[a b]) and
      int(S,v,[a;b]).  

syms x y;
f=x+2*y+1;
f1=int(f,x)%对x积分,把y当成常数
f2=int(f,x,2,4)%对x做2到4的定积分,把y当成常数
%%%%%%%%%%%%%
>> Untitled
f1 =x^2/2 + (2*y + 1)*x
f2 =4*y + 8                          


二、方程组求解


对方程和求解。

syms x y z ;
[x y z]=solve('x+y+z=10','3*x+2*y+z=14','2*x+3*y-z=1')
%g=solve('x+y+z=10','3*x+2*y+z=14','2*x+3*y-z=1', x,y,z);
%X=g.x
%Y=g.y
%Z=g.z;syms x y sina a b;

[x y]=solve('x*cos(sina)-y*sin(sina)=a','x*sin(sina)+y*cos(sina)=b',x,y)
>> Untitled
x = (a*cos(sina) + b*sin(sina))/(cos(sina)^2 + sin(sina)^2)
y = (b*cos(sina) - a*sin(sina))/(cos(sina)^2 + sin(sina)^2


 
  
 
  


三、符号积分变换


傅里叶正(反)Fourier(iFourier)变换、拉普拉斯)、拉氏变换l正(反) aplace(ilaplace)变换等。(待更)






你可能感兴趣的:(Matlab相关知识)