Mathcad lets you solve a system of up to fifty simultaneous equations in fifty unknowns. The first part of this section sketches the procedure. The remainder contains several examples as well as a discussion of some common errors. The method given here will always return numbers for the unknown variables. To see the unknowns in terms of the other variables and constants, use the symbolic solve blocks discussed in the section “Solving equations symbolically”
There are four steps to solving a system of simultaneous equations. These are:
• Provide an initial guess for all the unknowns you intend to solve for. Mathcad solves equations by making a series of guesses which ultimately converge on the right answer. The initial guesses you provide give Mathcad a place to start searching for solutions.
• Type the word Given. This tells Mathcad that what follows is a system of equations. You can type Given in any combination of upper and lower case letters, and in any font. Just be sure you don’t type it while in a text region or paragraph.
• Now type the equations and inequalities in any order below the word Given. Make sure you use the symbol “=” to separate the left and right sides of an equation. Press Solve blocks cannot be nested inside each other. Each solve block can have only one Given and one Find. You can however, define a function like f(x) := Find(x) at the end of one solve block and use this same function in another solve block. This too is discussed in the section “Using the solver effectively” on page 325.
As a rule, you should never use assignment statements (statements like x : = 1) inside a solve block. Mathcad marks assignment statements inside solve blocks with an appropriate error message.
Figure 15-6 shows a solve block with several kinds of constraints. There are two equations and two unknowns. As a result, the Find function contains two arguments, x and y, and returns a vector with two components.
What to do when the solver does not reach a solution
If the solver cannot make any further improvements to the solution but the constraints are not all satisfied, then the solver stops and marks the Find with an error message indicating that it was unable to find a solution.
If you are having difficulty finding a solution, it often helps to plot the curve or curves in question. Plotting can provide graphical insight into where the solution might be. This will help you choose appropriate initial guesses for the variables.
Figure 15-11 shows a problem for which Mathcad could not find a solution
The solver gives up trying to solve a system of equations whenever the difference between successive approximations to the solution is greater than TOL and:
• The solver reaches a point where it cannot reduce the error any further.
• The solver reaches a point from which there is no preferred direction. Because of this, the solver has no basis on which to make further iterations.
• The solver reaches the limit of its accuracy. Roundoff errors make it unlikely that further computation would increase accuracy of the solution. This often happens if you set TOL to a value below 10-15.
The following problems may cause this sort of failure:
• There may actually be no solution.
• You may have given real guesses for an equation with no real solution. If the solution for a variable is complex, the solver will not find it unless the starting value for that variable is also complex. Figure 15-11 shows an example.
• The solver may have become trapped in a local minimum for the error values. The solving method that Mathcad uses will sometimes reach a point from which it cannot minimize the errors any further. To find the actual solution, try using different starting values or add an inequality to keep Mathcad from being trapped in the local minimum.
• The solver may have become trapped on a point that is not a local minimum, but from which it cannot determine where to go next. The strategies for avoiding this problem are the same as those for avoiding a local minimum: change the initial guesses or add an inequality to avoid the undesirable stopping point.
• It may not be possible to solve the constraints to within the desired tolerance. If the value ofTOL is relatively small, Mathcad may have reached something very close to a solution but still be unable to solve all the constraints to an error less than TOL. Try defining TOL with a larger value somewhere above the solve block. Increasing the tolerance changes what Mathcad considers close enough to call a solution.
What to do when there are too few constraints
If there are fewer constraints than variables, Mathcad cannot run the solver at all. Mathcad then marks the Find with an appropriate error message.
A problem like that shown in Figure 15-12 is underdetermined. The constraints do not give enough information to find a solution. Because there are five arguments in the Find function, Mathcad thinks that you want to solve two equations with five unknowns.In general, such a problem has an infinite number of solutions.
To use the solver in Mathcad, you must provide at least as many equations as there are variables to solve for. If you specify the value of some of the variables, you may be able to solve for the remaining variables. Figure 15-13 shows how to fix the problem in Figure 15-12. Because the Find function contains only the arguments z and w,
Mathcad knows that you want x, y, and v to be held constant at 10, 50 and 0 respectively. A solve block with two equations becomes legitimate because there are now only two unknowns, z and w.