Sei sulla pagina 1di 17

Symbolic math toolbox

The Symbolic Toolbox is different from all other Matlab Toolboxes The Symbolic Toolbox is a collection of tools for manipulating and solving symbolic expressions Using a special version of the Maple Kernel, the Toolbox performs symbolic analysis using character strings, rather than numerical analysis on numerical arrays. When you pass a command to Matlab to perform a symbolic operation, it asks Maple to do it and return the result to the Matlab command window

Maple


The computation engine of the toolbox is the kernel of Maple,a symbolic computation software developed at University of Waterloo,Canada and recently by Eidgenissche Technische Zurich ,Switzerland and and marketed by Waterloo Maple Inc

Facilites of the toolbox

Here is a noteworthy example


        

Symbolic objects Sqrt(2) A=sqrt(sym(2)) Symbolic notation Symbolic expressions in matlab are given as character strings You can obtain numerical value form a symbolic object using Double(a); object overloading Symbolic objects are not indented Creating a fraction : sym(2)/sym(5)

symbolic objects
        

2/5+4/7 sym(2)/sym(5) +sym(4)/sym(7) Sym command lets you create symbolic variables and expressions Notice the @ sign at the workspace pane x= sym('x') a=sym('alpha') rho=sym((1+sqrt(5))/2);golden ratio F=rho^2-rho-1 To simplify the expression use simplify(F)

Sym..
           

For a quadratic equation Y=sym(a*x^2+b*x+c) or a=sym(a') b=sym(b') c=sym(c') x=sym(x') f=sym(a*x^2+b*x+c) or syms a b c x f=sym(a*x^2+b*x+c) solve(Y) Explicit declaration :syms a b F= a+b Syms f F;clear the variable A=Sym(5) a is not a variable

Findsym and subs


      

Fining symbolic objects in an expression Syms a b n t x z F=x^n;g=sin(a*t+b) Findsym(f); findsym(g) Substitution of value in expression:syms x f f=2*x^2+3*x+2 subs(f,2)

   

Syms f x y F=x^2*y+5*x*sqrt(y) Subs(f,x,2) Sub(f,y,3) Syms s t;g=s+t;Findsym(g,1) subs(cos(a)+sin(b),{a,b},{sym('alpha'),2})

 

Symbolic and numeric conversions


   

  

t=0.1 Sym(t,f); symbolic floating point representation of numeric value stored in t Sym(t,r) Sym(t,e);rational form of t plus the difference between theoretical and actual (machine) floating point value in EPS EPS returns the distance from 1.0 to the next largest floating point number format long e;eps;format rational Sym(t,d);32 bit decimal expansion of t

Real and complex


         

Digits(7); shorter representation Convert matrix from numeric to symbolic a=Hilb(3);sym(a) clearing variables in maple workspace maple restart x=sym(x,real) y=sym(y,real) Syms x y real Z=x+I*y F=x^2+y^2 Conj(x),conj(Z),expand(z*conj(z)) EXPAND(S) writes each element of a symbolic expression S as a product of its factors

      

SIMPLE(S) tries several different algebraic simplifications of S, displays any which shorten the length of S's representation and returns the shortest Syms x unreal collect(x^2*y + y*x - x^2 - 2*x) Abstract indeterminant function F=sym(f(x)) df=(subs(f,x,x+h)-f)/h a= 980 and C1 = 3; y = dsolve('Dy = -a*y') subs(y)

Symbolic matrix
   

Syms a b c A=[a b c;b c a;c a b] circulant Sum(A(1,:))=sum(A(:,2)) Syms alpha beta;A(2,3)=beta; A=subs(A,b,alpha)

Symbolic math functions


       

Syms x y z r=sqrt(x^2+y^2+z^2) f=sin(x*y)/(x*y) Diff(f) Int(ans) pretty(f) syms x;f = taylor(log(1+x)); Symbolic functions and m file are created in @sym directory

Sinc function- M file


        

function z=sinc(x) %symbilc sinc fiunction %sinx/x %accept sym as input argument if isequal(x,sym(0)) z=1; else z=sin(x)/x ; end

laplace
 

 

syms a t s laplace(diff(diff(sym('x(t)')))3*diff(sym('x(t)'))+2*sym('x(t)')) laplace(exp(a*s)) laplace(diff(sym('F(t)')))

Potrebbero piacerti anche