Using the solver effectively MathCad Help

This section provides some ideas on how to effectively exploit Mathcad’s ability to solve systems of simultaneous equations.

Repeatedly solving an equation

The techniques given thus far, while they are effective for solving a particular system of equations, are limited by two things:

• Every time you use a Find, you must have the rest of the solve block to go with it.

• If you want to change some of the parameters or constants in your system of equations to see how these affect the solution, you have to go all the way back to the solve block to change them.

Both these drawbacks are overcome by Mathcad’s ability to define a function in terms of a solve block.

If you define a function with Find somewhere on the right hand side, this function will solve the system of equations each time you use it. This overcomes the first problem.

If this function has as its arguments the same parameters that you want to vary in the solve block, you can simply change the parameters by changing the numbers you place in the function’s argument list. This overcomes the second problem.

Figure 15-14 shows a concrete example. The friction factor,f, of a pipe depends on the pipe’s diameter D, its roughness E, and the Reynolds number R. It’s quite conceivable that you would want to experiment with different size pipes (D) made of different typesof concrete (E).

The equation in Figure 15-14 shows the relationship between these parameters. The equation is too complicated to define a function of R, D and E simply by solving for f in terms of R, D and E. You can, however, define a function in terms of a solve block.

Whenever you ask Mathcad to evaluate the function FricFac(E, D, R), Mathcad takes the E, D, and R that you supply, replaces the corresponding variables in the solve block, solves for f, and returns the value.

Solving the same problem for different variables

You will occasionally run into a problem in which you want to change the roles of knowns and unknowns in an equation. For example, consider the equation that relates interest rate, loan amount, term of loan, and payments. If you know three of these four quantities, you can solve for the missing one.

The worksheet in Figure 15-17 shows that for a 12% loan on a 30-year mortgage and a payment of $1000 per month, the largest possible loan is $97,218.33.

Solving for the loan in a mortgage.

Solving for the loan in a mortgage.

With a few simple changes, the same worksheet can be used to solve for the interest rate. Suppose now that the amount of the loan is known to be $120,000. How far would interest rates have to drop to before the payments dropped to $1000 per month? Figure 15-18 shows the answer.

If you compare Figure 15-17 and Figure 15-18, you’ll see that they are very much the same. The main difference lies in the argument of the Find function. To change what is fixed and what is variable in an equation, simply change the arguments of the Find function.

Solving for the interest rate in a mortgage.

Solving for the interest rate in a mortgage.

Approximate solutions

Mathcad supplies a function very similar to Find called Minerr. This function uses exactly the same algorithm as Find. The difference is that if the solver cannot make any further improvements to the solution, Minerr returns a value anyway. The Find function on the other hand, will return an error message indicating that it could not find a solution. You use Minerr exactly the way you would use Find.

Minerr usually returns an answer that minimizes the errors in the constraints. However,Minerr cannot verify that its answers represent an absolute minimum  for the errors in the constraints. If you use Minerrin a solve block, you should always include additional checks on the reasonableness of the results. The built-in variable ERR gives the size of the error vector for the approximate solution. There is no built-in variable for determining the size of the error for individual solutions to the unknowns.

Minerr is particularly useful for solving certain nonlinear least-squares problems. Figure 15-19 shows an example in which Minerr is used to obtain the unknown parameters in a Weibull distribution. The function genfit is also useful for solving nonlinear least-squares problems. See  “Statistical Functions,” for more information on genfit.

Using the minerr function to do nonlinear least-squares fitting.

Using the minerr function to do nonlinear least-squares fitting.

Using the symbolic solver

You can usually find numerical roots quickly and accurately with Mathcad’s root function. But there are some circumstances in which you might want to use Mathcad’s symbolic solver find exact or approximate roots:

• If the equation you’re solving has a parameter, a symbolic solution may allow you to express the answer directly in terms of the parameter. Then instead of solving the equation over again for each new value of the parameter, you can just substitute its value into your symbolic solution.

• If you need all the complex roots of a polynomial of degree 4 or less, the symbolic solver will give them to you in a single vector, either exactly or numerically. The symbolic solver will also find complete solutions for some polynomials of higher degree.

See the section “Solving equations symbolically” in Chapter 17 for more information about solving equations symbolically

Posted on November 21, 2015 in Solving Equations

Share the Story

Back to Top
Share This