Transform Functions Root and Implicit
Introduction – Two new functions will be added to the transform language for solving equations. Equations to be solved can be written using of any of the transform language’s numeric functions and operators, and it can contain any number of variables, but only one of the variables can be designated as the solution variable. These functions do not attempt to find a simultaneous solution to a system of equations nor do they find solutions which are not real numbers.
Description of the root function – The root function is used to find the roots of a function of one variable over a finite interval. In other words, the root function solves equations of the form f(x) = 0, where x is restricted to lie in a finite interval. This function also has the capability of finding certain values of the independent variable where the function is undefined, known as isolated singularities.
The syntax is:
rv = root(expr, variable, a, b, maxroots, type).
- expr This is the expression that defines the equations to solve. The expression can specify a range or list of functions so that more than one equation can be solved at a time. The equations are defined by setting each function in the expression list equal to zero.
- variable This is the symbol for the variable you are solving for in each specified equation. The same variable is used for all equations.
- a and b are the left and right endpoints, respectively, of the interval over which the root search takes place. For this function to execute successfully, the value of expr must be well-defined at the value of each endpoint.
- maxroots This is the maximum number of roots to compute for each specified function in the first argument. The default value is 1.
- type This is a number that specifies one of two types of output. If type = 0, then only roots will be returned. If type = 1, then only singularities will be returned. The default value is 0.
rv This is the list or range of all of the roots that were found. The number of values returned will always be equal to maxroots for each function specified in the first argument. If fewer roots than maxroots are found, then the remaining values returned will be missing values. The reason for inserting the missing values is so the output of the different functions can be distinguished.
- Increasing the value of maxroots will increase the chances of finding all of the roots of the function in the prescribed interval. It will also increase the time required to complete the processing of the root function.
- When searching for multiple solutions to an equation, the root function partitions the user-specified interval into maxroots equally-spaced subintervals. It then searches each subinterval for exactly one solution. As a consequence, the root function may return fewer than maxroots solutions, even though the equation actually has maxroots or more solutions in the supplied interval. Ideally, to find all of the solutions to the equation over the interval from a to b, set maxroots to a value greater than (b -a)/delta, where deltaestimates the closest distance between any solutions.
- The output of the root function is always sorted to give the roots in ascending order for each function in expr.
Description of the implicit function – In applications, a function is often defined implicitly by an equation involving a dependent variable and one or more independent variables. The implicit function is used to solve the equation for the dependent variable when a value for each independent variable has been specified.
The syntax is:
rv = implicit(expr, a, b, indvar, maxroots, firstroot).
- expr This is the expression containing the dependent variable and the independent variables. The equation is defined by setting this expression equal to zero. The expression must be a user-defined function. For example, the user-defined function might be
k(u,v) = u^2 3*u*v + v^2
and the equation being solved becomes k(u,v) = 0. In this case, you would set the first argument in the implicit function to k(u,v).
It is assumed that the dependent variable (the solution variable) is always the first variable in the argument list of the user-defined function. In the above example, this variable is u.
The argument list can have any number of independent variables. For example,
r(u,v,w) = (u+v*w)*exp(u*w).
In this case, u is the dependent variable with v and w as the independent variables.
The user-defined function may contain other variables than those in its argument list. These parameters are assumed to have assigned values when the function is defined. It is important that each parameter be a scalar quantity defined by a single numeric value. If any parameter is a range, then only the first value in that range is used.
- a and b are the left and right endpoints, respectively, of the interval over which the solution search for the dependent variable takes place. For this function to execute successfully, the value of expr must be well-defined at the value of each endpoint.
- indvar This is an expression or symbol that defines the values of the independent variables that are used to solve the equation. It is usually defined by some range. For example, suppose we have the transform:
Then this transform takes a value from column 1, assigns it to the variable v, and solves the equation k(u,v)=0 for the variable u. This is then repeated until all values in column 1 have been used. The results are then assigned to the variable f.
If more than one independent variable is listed in the user-defined function, then the values of the independent variables are concatenated in the order they appear in the function and the result is assigned to indvar. For example, in the transform below we have the implicit function used with two independent variables:
In this example, a value from column 1 is assigned to the variable v and a value for column 2, in the same row, is assigned to variable w. The equation k(u,v,w) is then solved for the variable u. This process is repeated until there are no more entries in columns 1 and 2.
It is important to note that when a range of data is provided to the argument indvar, then that data is divided equally among the independent variables in the equation. The data will be partitioned this way, beginning with the first independent variable, and the implicit function will ignore the remainder.
For example, if indvar is provided a range of 14 values and there are 3 independent variables in the problem, then the values 1-4 will be assigned to the first variable, values 5-8 will be assigned to the second variable, and values 9-12 will be assigned to the third variable. The last two values will be ignored.
- maxroots This is the maximum number of dependent variable values to compute when each independent variable has a specified value. The default value is 1.
- firstroot This is a numeric flag to indicate how the function returns the solutions. The default value is zero.
rv When the argument firstroot has the default value 0, this is the list or range of all of the solutions that were found. The number of values returned will always be equal to maxroots for each set of independent variable values. If fewer solutions than maxroots are found, then the remaining values returned will be missing values.
The reason for returning exactly maxroots results, whether a missing value is included or not, is so the output for different values of the independent variables can be distinguished.
If firstroot has the value 1, then only the first solution found for specified values of independent variables will be returned. If no solution is found, then the returned value is a missing value.
- Increasing the value of maxroots will increase the chances of finding all of the solutions of the equation in the prescribed interval. It will also increase the time required to complete the processing of the implicit function.
- When searching for multiple solutions to an equation, the implicit function partitions the user-specified interval into maxroots equally-spaced subintervals. It then searches each subinterval for exactly one solution. As a consequence, the implicit function may return fewer than maxroots solutions, even though the equation actually has maxroots or more solutions in the supplied interval. Ideally, to find all of the solutions to the equation over the interval from a to b, set maxroots to a value greater than (b -a)/delta, where deltaestimates the closest distance between any two solutions.
- The output of the implicit function is always sorted to give the solutions in ascending order for each selection of values for the independent variables.
Examples Using root and implicit
Example 1: This example uses a range of values to create a list of slightly modified equations. Two roots are found for each of the equations and the values are returned to the worksheet. Since v is a formal argument to a user-defined function, its value need not be initialized.
Example 2: Finds the two roots of the equation x^2+3*x-7=0. Note that x is initially set to 1 since each variable that is used in the transform language must be initialized unless it is a formal argument in a user-defined function as in the example above. The value that x is initially set to doesn´t matter.
Example 3: Same equation as above, but more direct.
Example 4: This example uses range notation to enter multiple functions in the first argument of the root function. In this case, two roots are computed for each of three functions and the six values are returned to the worksheet.
It is assumed that the angular unit for this transform has been set to radians so that the value of x is interpreted in units of radians when finding the roots of g. In the output, the roots of function f are listed first, followed by the roots of the other two functions according to the order in which they appear in the list.
Example 5: Finds a solution of the equation a*u^b/(c^b+u^b) – v =0 for each value of v in the sampled data from the interval from 0 to 10. The results are written to column 1.
k(u,v)=a*u^b/(c^b+u^b) – v
Example 6: Graphing an implicit equation with two variables can be difficult. The obvious way is to select several values of one variable, which will be referred to as the independent variable, and solve the equation for the remaining variable, which will be the dependent variable.
In order to get the complete graph of the equation over a given range of values for the independent variable, we need to obtain all of the solutions of the equation for the dependent variable.
Suppose we wish to graph the equation sin(x)^2 = y*(y-1)*(y-2) for values of x between -5 and 5. It is clear that the y values for this equation must be greater than 0, otherwise sin(x)^2 would be negative, which is impossible. Also, any y value must be less than 3, otherwise the right side of the equation would be greater than 1, which is the largest value of sin(x)^2. Thus, we will choose our search interval for y between 0 and 3.
Looking at the equation, we see that for each value of x there are at most 3 values of y since the right side of the equation is a cubic polynomial. Knowing this, we could set maxroots equal to 3. However, from the discussion in the remarks above, since we don´t know how close the solutions are for a given x value, we will set this value higher to maxroots = 10.
The transform below generates the data that will be used to obtain the graph (remember to set the trigonometric units to radians).
for i=1 to size(x) do
for j = 1 to 10 do
cell(1,10*(i-1) + j) = x[i]
The first line samples several values of the independent variable over the interval from -5 to 5. The second line defines the expression that will be set to zero to give us the equation. The call to the implicit function in the third line contains our information for the search interval and maxroots.
Because of how the implicit function arranges the output, with all solutions for each x-value displayed consecutively, the remaining lines of the transform arrange our x-data in the worksheet by repeating a value for the 10 corresponding solutions.
Note that there will be many missing values in the output of the implicit function since we know that a maximum of three values is all we expect. When graphing, these missing values will simply be ignored. Before running the transform, make sure that radians is selected as the angular units.
After running the transform, select the Create Graph ribbon menu and choose Simple Scatter Plot with columns 1 and 2 selected for the XY Pair data format. The resulting graph is:
The three nearly closed curves below the undulating curve should indeed be closed, but more sampled points are needed.