I am just getting started with Maple TA for Calc III. I am trying to solve LaGrange multipliers. When the solve command returns multiple sets of answers, how do I extract the specific values for the subs command?
$f=xyz;
$q=x^2+2y^2+3z^2-6;
$g=maple("f+mu*$q");
$exp1=maple("diff($g,x)");
$exp2=maple("diff($g,y)");
$exp3=maple("solve({$q,$exp1,$exp2},[x,y,mu])");
$ans1=maple("subs({x = ????,),y =???? )},$f)");
$ans2=maple("subs({x = ????,y = ????},$f)");
The question marks are where I am lost.
Comments
Sequences, list, and sets
I'm not quite sure whether this answer of mine is what your are looking for, but generally when working with sequences, lists, sets, etc., an index is used to extract a particular item. An example (the quadratic equation) using solve:
For nested sequences, lists, sets, etc., several indices are used. An example:
nested := [{1,2,3},{a,b,c}]; nested[1]; nested[2]; nested[1][2]; nested[2][3];appreciate the help but it
appreciate the help but it is not working. I would guess that when you say nested[1][2], you are indicating that the value returned is the second value in the first set. If I try that, I just get the set listed with indicies on my variables.
If you see my original code, and put $exp3[2][1]into the first set of ????, it does not acknowledge that I am trying to retreive a single value from the list.
Difficulties
The reason why my former answer was quite general is that I'm having difficulties understanding your code:
First, the syntax, using $'s for instance, is unknown to me. A $ sign in front of variables is used for instance in the web programming language PHP, but not in Maple (as far as I know).
Second, I'm unable to disentangle your code; could you break it down, or explain to me the purpose or the origin of it?
Perl-like syntax
John, I thought the exact same thing about that syntax when I first saw it.
I use to program in Perl before they came along with PHP for the web which uses a similar syntax. PHP incorporates a lot of languages, including Perl, so you'll find it a lot in there as well.
I think one of the programming languages for a PIC based microcontroller by Parallax also uses the dollar signs for defining variables.
This is Maple TA
In Maple TA all variables are defined with a $ in front of them, such as my espressions $f, $q, and $g. Variables which are unknown such as x,y,z, and mu do not have the $ as they can be solved for.
I taking the partial differentials of g with respect to x and y and then solving for the three unknowns with the solve command. I then need to replace those variable "names" or values in the f command for the original x and y so that I can solve for z. I will nest this in a loop so that all x and y values are evaluated but at this time, I am just trying to retreive one set so that I can see what I am doing.
The solve returns two sets of answers and I am not having any luck retreiving the individual values.
Any help is great. It is very confusing to have the syntax different in Maple and Maple TA. Not a great choice on their part.
Thanks
Using Maple
I've translated your lines to Maple code:
f := x*y*z: q := x^2+2*y^2+3*z^2-6: g := f+mu*q: exp1 := diff(g,x): exp2 := diff(g,y): exp3 := solve({q,exp1,exp2},{x,y,mu}): ans1 := subs({x = 1,y = 2},f); ans2 := subs({x = 2,y = 3},f); ans1 := 2 z ans2 := 6 zIn doing so, I noticed some typos in your code:
1. Missing * between x, y, and z for f, as well as elsewhere (I don't know whether they are mandatory or not in Maple TA).
2. In the expressions for ans1 and ans2, (...) and {...} are nested wrongly.
3. In the expression for exp3, you use [...] brackets around x, y, and mu. I think you have to use {...} brackets, as indicated.
As you can see, for x and y in the "subs" lines I've chosen some numbers at random.
I hope that was of some help.
something I tried
Before John came back with his really great answer, I tried to work out a solution for you in Maple 11 and posted an example of it. The link to an HTML showing what I did as well as a link to the Maple 11 worksheet within the HTML is shown below
HERE
I've never done anything quite like this, so I wanted to at least give it a go and maybe there is something at least a little worthwhile in it that you can use.
I'm probably as new to Maple as you are, and just got back into learning math a short while ago as well.
How to reference the values from the solve command for x, y and
Where you placed the actual numbers, I need to put an reference to the value returned from the solve command in the line above. I can't get the references right. The solve command returns two sets of values for the three variables. If I want to use the x and y from the first set of solutions, how do I reference them?
ans1:=subs({x=expr3[1,1],y=expr3[1,2]},f);
This does not work. It does not return the value defined in the set of solve solutions
It's slowly coming back to me
Now I begin to see where you want to go (it is almost twenty years ago I learned above Lagrange multipliers, so I've just had to consult my old book on linear algebra about the subject).
You seem to be missing the differentiation with respect to the third variable, z. I've rewritten you code as follows:
f := x*y*z: q := x^2+2*y^2+3*z^2-6: g := f+mu*q: diff_x := diff(g,x): diff_y := diff(g,y): diff_z := diff(g,z): sols := solve({q = 0,diff_x = 0,diff_y = 0,diff_z = 0},{x,y,z,mu}):There seems to be five different solutions (maybe I'm mistaken), which may be accessed as follows (with $'s and the like in your case, of course):
For instance taking the first,
sols[1]; {mu = 0, z = 0, x = RootOf(_Z^2-6), y = 0}the values may be retrieved as follows:
Thanks for the teriffic help.
I am just getting going with this whole concept and I had to jump in a little deeper than I have experience with. Your help has been teriffic. Now on to solving for the extreme values and saddle points!