Solving Equations MathCad Help

This chapter describes how to solve equations ranging from a single
equation in one unknown to systems of up to fifty equations in fifty unknowns. The techniques described here generate numeric solutions.”Symbolic Calculation,” describes a variety of techniques for solving equations symbolically.

The following sections make up

Solving one equation
How to use Mathcad’s root function to numerically solve one equation in one unknown.

Systems of equations
How to use “solve blocks” to solve systems of n equations in n unknowns.

Using the solver effectively
Examples of how to solve systems of equations efficiently for various values of a parameter.

Solving one equation

To solve a single equation in a single unknown, use the root function. This function takes an expression and one of the variables from the expression. It then varies that variable until the expression is equal to zero. Once this is done, the function returns the value that makes the expression equal zero.

Returns the value of z at which the expression or functionj(z) is equal to O. Both arguments to this function must be scalar. The function returns a scalar

The first argument is either a function defined elsewhere in the worksheet, or an expression. It must return a scalar value.

The second argument is a variable name that appears in the expression. It is this variable that Mathcad will vary to make the expression go to zero. You should assign a number to this variable before using the root function. Mathcad uses this as a starting value in its search for a solution.

For example, to define a as the solution to the equation <Insert equation here>, follow these steps:

• Define a guess value for x. Type x: 3. Your choice of guess value determines which root Mathcad returns

solving equtions

solving equtions

When you use the root function, keep these suggestions in mind:

• Make sure that the variable is defined with a guess value before you use the root function.

• For expressions with several roots, for example x2 – 1 = 0, your guess value determines which root Mathcad will return. Figure 15-1 shows an example in which the root function returns several different values, each of which depends on the initial guess value.

• Mathcad will solve for complex roots as well as real roots. To find a complex root, you must start with a complex value for the initial guess.

• Solving an equation of the form f(x) = g(x) is equivalent to using the root function as follows

solving equatrion

solving equatrion

The root function can solve only one equation in one unknown. To solve several equations simultaneously, use the technique described in the next section, “Systems of Equations.” To solve an equation symbolically, or to find an exact numerical answer in terms of elementary functions, choose Solve for Variable from the Symbolic menu or use the solve keyword. See Chapter 17, “Symbolic Calculation

Using a plot and the root function tofind roots of an expression.

Using a plot and the root function tofind roots of an expression.

What to do when the root function does not converge

Mathcad evaluates the root function using the secant method. The guess value you supply for x becomes the starting point for successive approximations to the root value. When the magnitude ofj{x) evaluated at the proposed root is less than the value of the predefined variable TOL, the root function returns a result.

If after many approximations Mathcad still cannot find an acceptable answer, it marks the root function with an error message indicating its inability to converge to a result. This error can be caused by any of the following:

• The expression has no roots.
• The roots of the expression are far from the initial guess.
• The expression has local maxima or minima between the initial guess and the roots.
• The expression has discontinuities between the initial guess and the roots.
• The expression has a complex root but the initial guess was real (or vice versa).

To find the cause of the error, try plotting the expression. This will help determine whether or not the expression crosses the x-axis and if so, approximately where it does so. In general, the closer your initial guess is to where the expression crosses the x-axis, the more quickly the root function will converge on an acceptable result.

Hints on using the root function

Here are some hints on getting the most out of the root function:

• To change the accuracy of the root function, change the value of the built -in variable TaL. If you increase TaL, the root function will converge more quickly, but the answer will be less accurate. If you decrease TaL, the root function will converge more slowly, but the answer will be more accurate. To change TaL at a specified point in the worksheet, include a definition like TOL := 0.01 . To change TaL for the whole worksheet, choose Options from the Math menu, click on the Built-In Variables tab, and replace the number in the text box beside “TaL.” After you click “OK,” choose Calculate Worksheet from the Math menu to update the entire worksheet using the new value of TaL.

• If an expression has multiple roots, try different guess values to find them. Plotting the function is a good way to determine how many roots there are, where they are, and what initial guesses are likely to find them. Figure 15-1 shows an example of this. If two roots are close together, you may have to reduce TaL to distinguish
between them.

• If fix) 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 It( r)1 < TO L , r may be far from the point where f( r) = O. To find a more accurate root, decrease the value of TaL. Or, try finding root(g(x),x), where

Hints on using the root function

Hints on using the root function

• For an expre ionfix) with a known root a, solving for additional roots of fix) is equivalent to olving for roots of hex) = (f(x))/(x – a). Dividing out known roots like this . eful for resolving two roots that may be close together. It’s often easier to olve for roots of hex) as defined here than it is to try to find other roots for fix) with different gue ses

Solving an equation repeatedly

Suppose you want to solve an equation many times while varying one of the parameters in the equation. For example, suppose you want to solve the equation eX = a· x2 for several different values of the parameter a. The simplest way to do this is to define a function:

Solving an equation repeatedly

Solving an equation repeatedly

To solve the equation for a particular value of a, supply both a and a guess value, x, as arguments to this function. Then evaluate the unction by typing f (a, x) =.

Figure 15-2 shows an example of how such a function can be used to find several solutions to the root function. Note that since the guess value, x, is passed into the function itself, there is no need to define it elsewhere in the worksheet.

Defining a user function with the root function.

Defining a user function with the root function.

Finding the roots of a polynomial

To find the roots of an expression having the form:

Finding the roots of a polynomial

Finding the roots of a polynomial

you can use the polyroots function rather than the root function. Unlike root, polyroots does not require a guess value. Moreover, polyroots returns all roots at once, whether real or complex. Figure 15-3 and Figure 15-4 show examples.

Using polyroots to do the example shown in

Using polyroots to do the example shown in

The polyroots function will always return numerical values for the roots of a polynomial. To find the roots symbolically, use the solve symbolic keyword or choose Solve for Variable from the Symbolic menu. See Chapter 17, “Symbolic Calculation.”

Using polyroots to find the roots of a polynomial.

Using polyroots to find the roots of a polynomial.

Posted on November 21, 2015 in Solving Equations

Share the Story

Back to Top
Share This