next up previous contents
Next: Simplifying and Collecting Expressions Up: Symbolic Transformations Previous: Symbolic Transformations

Substitution

Parts of an expression may be replaced by other expressions using subst(a,b,c): a is substituted for b in c. This is a powerful function with many uses.

First, it may be used to insert numbers for variables, in the example $3$ for $x$ in der formula $2\sqrt{x}\cdot e^{-x^2}$.

>> syms x
>> a=2*sqrt(x)*exp(-x^2);
>> subst(3,x,a)             
ans = 4.275E-4

Second, one can replace a symbolic variable by a complex term. The expression is automatically updated to the canonical format. In the following example $z^3+2$ is inserted for $x$ in $x^3+2x^2+x+7$.

>> syms x,z
>> p=x^3+2*x^2+x+7;
>> subst(z^3+2,x,p)         
ans = z^9+8*z^6+21*z^3+25

Finally, the term b itself may be a complex expression (in the example $z^2+1$). Jasymca then tries to identify this expression in c (example: $\frac{z\cdot x^3}{\sqrt{z^2+1}}$). This is accomplished by solving the equation $a = b$ for the symbolic variable in b (example: $z$), and inserting the solution in c. This does not always succeed, or there may be several solutions, which are returned as a vector.

>> syms x,y,z
>> c=x^3*z/sqrt(z^2+1);
>> d=subst(y,z^2+1,c)
d = [ x^3*sqrt(y-1)/sqrt(sqrt(y-1)^2+1)  
     -x^3*sqrt(y-1)/sqrt(sqrt(y-1)^2+1) ]
>> d=trigrat(d)
d = [ x^3*sqrt(y-1)/sqrt(y)  
     -x^3*sqrt(y-1)/sqrt(y) ]


next up previous contents
Next: Simplifying and Collecting Expressions Up: Symbolic Transformations Previous: Symbolic Transformations
Helmut Dersch
2009-03-15