LearningGuide

eval eqns soln1 1 1 3 3 eval eqns soln2

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

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: &gt; 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 ﬁrst give the set of equations a name, like eqns, for instance. &gt; eqns := {x+2*y=3, y+1/x=1}; eqns := {x + 2 y = 3, y + 1 = 1} x Then solve. &gt; soln := solve( eqns, {x,y} ); 1 soln := {x = −1, y = 2}, {x = 2, y = } 2 This produces two solutions: &gt; soln[1]; {x = −1, y = 2} and &gt; 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. &gt; eval( eqns, soln[1] ); {1 = 1, 3 = 3} &gt; eval( eqns, soln[2] ); {1 = 1, 3 = 3} 46 • Chapter 3: Finding Solutions For verifying solutions, you will ﬁnd 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 ﬁrst solution, use the eval command. &gt; x1 := eval( x, soln[1] ); x1 := −1 Alternatively, you could extract the ﬁrst solution for y . &gt; 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 ﬁrst solution where x is the ﬁrst element and y is the second. First construct a list with the variables in the same order as you want the corresponding solutions. &gt; [x,y]; [x, y ] Evaluate this list at the ﬁrst solution. &gt; eval([x,y], soln[1]); [−1, 2] The ﬁrst solution is now a list. Instead, if you prefer that the solution for y comes ﬁrst, evaluate [y,x] at the solution. &gt; 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 speciﬁed as its ﬁrst argument to its second argument. &gt; 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, &gt; soln; 1 {x = −1, y = 2}, {x = 2, y = } 2 Enclose soln in square brackets to convert it to a list. &gt; [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. &gt; map(subs, [soln], eqns); [{1 = 1, 3 = 3}...
View Full Document

Ask a homework question - tutors are online