January 2020
Intermediate to advanced
880 pages
21h 22m
English
To declare any variable(s) as a symbolic variable, you should use the sym or syms command as follows:
>>a=sym('a'); x=sym('x'); y=sym('y'); t=sym('t'); n=sym('n');>>syms a x y t n %or, equivalently and more efficiently
Once the variables have been declared as symbolic, they can be used in expressions and as arguments to many functions without being evaluated as numeric.
>>f=x^2/(1+tan(x)^2);>>ezplot(f,-pi,pi) % easy plot of f for [-π,+π]>>simplify(cos(x)^2+sin(x)^2) % simplify an expressionans= 1>>simplify(cos(x)^2-sin(x)^2) % simplify an expressionans= 2*cos(x)^2-1>>simplify(cos(x)^2-sin(x)^2) % simple expressionans= cos(2*x)>>simplify(cos(x)+i*sin(x)) % simple expressionans= exp(i*x)>>eq1=expand((x+y)^3-(x+y)^2) % expandeq1= x^3+3*x^2*y+3*x*y^2+y^3-x^2-2*x*y-y^2>>collect(eq1,y) % collect similar terms in descending order w.r.t. yans= y^3+(3*x-1)*y^2+(3*x^2-2*x)*y+x^3-x^2>>factor(eq1) % factorizeans= (x+y-1)*(x+y)^2>>horner(eq1) % nested multiplication formans= (-1+y)*y^2+((-2+3*y)*y+(-1+3*y+x)*x)*x>>pretty(ans) % pretty form2(-1 + y) y + ((-2 + 3 y) y + (-1 + 3 y + x) x) x
If you need to substitute numeric values or other expressions for some symbolic variables in an expression or take the limit of an expression, you can use subs( ) and limit( ) as follows:
>>subs(eq1,x,0) % substitute numeric value x=0 into eq1=(x+y-1)*(x+y)^2 ...Read now
Unlock full access