eval eqns soln1 1 1 3 3 eval eqns soln2

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: > solve({x+2*y=3, y+1/x=1}, {x,y}); 1 {x = −1, y = 2}, {x = 2, y = } 2 Returning the Solution as a Set Although you do not always need the braces (denoting a set) around either the equation or variable, using them forces Maple to return the solution as a set, which is usually the most convenient form. For example, it is a common practice to check your 3.1 The Maple solve Command • 45 solutions by substituting them into the original equations. The following example demonstrates this procedure. As a set of equations, the solution is in an ideal form for the subs command. You might first give the set of equations a name, like eqns, for instance. > eqns := {x+2*y=3, y+1/x=1}; eqns := {x + 2 y = 3, y + 1 = 1} x Then solve. > soln := solve( eqns, {x,y} ); 1 soln := {x = −1, y = 2}, {x = 2, y = } 2 This produces two solutions: > soln[1]; {x = −1, y = 2} and > soln[2]; 1 {x = 2, y = } 2 Verifying Solutions To check the solutions, substitute them into the original set of equations by using the two-parameter eval command. > eval( eqns, soln[1] ); {1 = 1, 3 = 3} > eval( eqns, soln[2] ); {1 = 1, 3 = 3} 46 • Chapter 3: Finding Solutions For verifying solutions, you will find that this method is generally the most convenient. Observe that this application of the eval command has other uses. To extract the value of x from the first solution, use the eval command. > x1 := eval( x, soln[1] ); x1 := −1 Alternatively, you could extract the first solution for y . > y1 := eval(y, soln[1]); y1 := 2 Converting Solution Sets to Other Forms You can use this evaluation to convert solution sets to other forms. For example, you can construct a list from the first solution where x is the first element and y is the second. First construct a list with the variables in the same order as you want the corresponding solutions. > [x,y]; [x, y ] Evaluate this list at the first solution. > eval([x,y], soln[1]); [−1, 2] The first solution is now a list. Instead, if you prefer that the solution for y comes first, evaluate [y,x] at the solution. > eval([y,x], soln[1]); [2, −1] Since Maple typically returns solutions in the form of sets (in which the order of objects is uncertain), remembering this method for extracting solutions is useful. 3.1 The Maple solve Command • 47 Applying One Operation to All Solutions The map command is another useful command that allows you to apply one operation to all solutions. For example, try substituting both solutions. The map command applies the operation specified as its first argument to its second argument. > map(f, [a,b,c], y, z); [f(a, y, z ), f(b, y, z ), f(c, y, z )] Due to the syntactical design of map, it cannot perform multiple function applications to sequences. Consider the previous solution sequence, for example, > soln; 1 {x = −1, y = 2}, {x = 2, y = } 2 Enclose soln in square brackets to convert it to a list. > [soln]; 1 [{x = −1, y = 2}, {x = 2, y = }] 2 Use the following command to substitute each of the solutions simultaneously into the original equations, eqns. > map(subs, [soln], eqns); [{1 = 1, 3 = 3}...
View Full Document

Ask a homework question - tutors are online