How to maximize , minimize and root of function On MathCAD
Finding Roots
The root of a function is the value at which the function equals zero.
• root(f(var1, var2, ...), var1, [a, b])—Returns the value of var1 to make the function f equal to zero. If a and b are specified, root finds var1 on the interval [a, b]. Otherwise, var1 must be defined with a guess value before root is called. When a guess value is used, root uses the secant or Mueller’s method; in the case where root bracketing is used, root uses Ridder’s or Brent’s method.
Arguments
• f is a scalar-valued function of any number of variables.
• var1 is a scalar variable found in f, the variable with respect to which the root is found. Define a complex guess to solve for a complex root.
• a, b (optional) are real numbers, a < b, such that f(a) and f(b) have opposite signs. root searches for a root on the interval a ≤ x ≤ b.
You must specify the range arguments [a, b] when evaluating the root function symbolically.
• v is a vector containing coefficients of a polynomial in which the first element is the constant term, and 2 ≤ length(v) ≤ 99.
Additional Information
• Inserting the root function from the Ribbon automatically assigns it the Keyword label.
• The root function can only solve one equation in one unknown. To solve several equations simultaneously, use find or minerr.
• The root function is dependent on TOL, but does not respond to a TOL that is larger than 10-5. This is the maximum convergence criteria. In addition, values of TOL smaller than 10-12 are not likely to produce superior results, while the algorithm may fail to converge.
• For functions with multiple roots, the returned root depends on the guess value. If the guess value is very close to a minimum or maximum of f, the root function may fail to converge or converge to a root far away from the guess value. In choosing an appropriate guess value or brackets, it helps to graph the function beforehand.
• Functions with rapid variation can cause the root solver to return tiny complex parts even when a real result is expected.
• To solve an equation of the form f(x) = g(x), use an expression like x0 := root(f(x) − g(x), x)
• For an expression f(x) with a known root r, solving for additional roots of f(x) is equivalent to solving for roots of h(x) = f(x) / (x − r). Dividing out known roots like this is useful for resolving two roots that may be close together. It is often easier to solve for roots of h(x) as defined here than it is to try to find other roots for f(x) with different guesses.
• If f(x) has a small slope near its root, then root(f(x), x) may converge to a value r that is relatively far from the actual root. In such cases, even though |f(r)|<TOL, r may be far from the point where f(r) = 0. To find a more accurate root, decrease the value of TOL. Or, try finding root(g(x),x), where g(x) = [f(x))]/[(d/dx)*f(x)]).
• The root function may fail to converge, or may converge to an unexpected root, if:
◦ There are no roots to the expression.
◦ The roots are too far from the initial guess.
◦ There is a local maximum, a local minimum, or a discontinuity between the guess value and the roots.
◦ The guess value is very close to a minimum or a maximum of function f.
◦ The expression has a complex root but the initial guess is real (or vice versa).
◦ There are multiple closely-spaced roots—Try reducing the value of TOL to distinguish between them.
◦ The roots are in flat regions of the function—Try reducing the value of TOL, or finding the root of the f(x) function divided by its first derivative.
Optimization Functions
• maximize(f, var1, var2, ...), minimize(f, var1, var2, ...)—Return values for all the arguments of the objective function f so that the constraints in a solve block are satisfied, and function f takes on its largest or smallest value, respectively.
When the function has one argument only, the solution is a scalar. Otherwise, the solution is a vector where the first element is the solution to var1, the second element is the solution to var2, and so on. PTC Mathcad Prime adjusts all the argument values simultaneously to minimize the error.
Arguments
• f is the objective function to minimize or maximize. You must supply f without its arguments to the solve block function.
• var1, var2, ..., are the guess values for each of the arguments of the objective function f. The order in which you enter the guess values must be the same as the argument order for the objective function. When the solve block contains more than one guess value, you must pass all the values as arguments to the maximize or minimize function.
Additional Information
• For unconstrained function optimization, you can use the maximize and minimize functions outside a solve block. PTC Mathcad Prime ignores constraints that you specify outside solve blocks.
• Legacy PTC Mathcad functions Maximize and Minimize are interchangeable with maximize and minimize respectively.
• Inserting the lowercase functions from the Ribbon, or manually typing the lower/upper case versions, automatically assigns them the Keyword label.
• Functions maximize and minimize use the KNITRO solving algorithm.
• The order of the parameters returned by maximize and minimize matches the order of arguments of function f.
• When you add constraints to an optimization problem, you must have fewer equality constraints than optimization variables. Otherwise the constraints will usually fix the values of the variables in such a way that there is nothing to optimize. On the other hand, you can have any number of inequality constraints.
• Guess values that you provide must satisfy the specified constraint.
Example(continou)
Watch full Video
Password: @mathcadforengineering
0 Comments