Note that the first argument to subs was the symbolic expression being substituted into, the second is the value being substituted for x We can also substitute other symbolic variables and even entire symbolic expressions - into other symbolic expressions using the subs function, as demonstrated in the commands below syms x a y sqrt(x) z1 subs(y,a) z2 subs(y,2*a+1) The result of these commands are two new symbolic expressions: z1 equal to va z2 equal to /2a+ Note that we don't have to specify which variable we are substituting for if the expression only contains one symbolic variable. For example, the code below creates the symbolic expression y equal tocos (2x) substitutes pi for the symbolic variable x syms x y cos (x) z subs (y,pi The result is the symbolic variable z equal to 1 (as cos (2) 1). To do this with an existing symbolic expression in MATLAB, we use the subs function. For example, we might like to substitute the value r forx in the expression cos (2x) and obtain the result. Evaluating Symbolic Expressions Using Substitution 0 solutions submitted (max: 5) When working with symbolic expressions, a common task is to substitute a particular value into the expression for one of the symbolic variables that make up that expression.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |