Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 cosx
z subsypi
The result is the symbolic variable z equal to 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 sqrtx
z subsya
z subsya
The result of these commands are two new symbolic expressions:
z equal to
z 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 xy
subszy
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 for x in f and store the result in the variable val
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 x in ff and store the result in the variable val
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started