Question: 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

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. For example, we might like to substitute the value for in the expression and obtain the result. To do this with an existing symbolic expression in MATLAB, we use the subs function. For example, the code below creates the symbolic expression y equal to 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 . 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
z2 equal to
Note that we don't have to specify which variable we are substituting for if the expression only contains one symbolic variable. To substitute into an expression that contains multiple symbolic variables, specify the expression followed by the name of the variable you are substituting for and the variable or expression you are replacing it with, as in the example below which substitutes for in the expression :
syms x y
z = x^2+y^2
subs(z,y,1)
Your Task
Below you will substitute values and symbolic expressions into other symbolic expressions. The symbolic expression f, equivalent to , has been defined for you in the solution template, along with the symbolic variables x and y. Follow the steps below to complete the script:
Use the subs function to substitute x for y in the expression f and assign the result back to f, so that f is now a symbolic expression of x.
Substitute the value 0.25 for x in f and store the result in the variable val1
Obtain the composition of f with itself by substituting f for x in f. Store the resulting expression in the variable ff.
Substitute the value of 0.75 x in ff and store the result in the variable val2.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!