I have something like
solutions := solve ( {eqn1=0, eqn2=0, eqn3=0, eqn4=0, ... } )
which returns something like:
solutions := {Ax = -.2312688085, Ay = -7.770329620, Bx = -19.76873119, ....}
How can I access and save each solution?
Is "Ax := solutions[1];", and so on, the only way?
Although solutions[1] doesn't access to -.2312688085 in the above example, but a kind of string "Ax = -.2312688085", so I end up having "Ax := Ax = -.2312688085"
The eval
command allows you to use the solution just as if Ax,Ay,etc had been assigned, when evaluating other expressions involving those names. You get this effect without having to actually make the assignments (a benefit of which is that you can then create other equations in those variables without having to unassign their names).
An alternative approach is to use assign
command to actually make assignments of the returned numeric values to those variable names. But this makes subsequent attempts to use those symbolic variables names more awkward -- you'd have to first unassign them. You might not want to get into a awkward pattern of having to assign/unassign over and over.
Using eval
is easier, I think. But you can try both, of course, and use what you prefer.
Some examples might help:
restart:
eq1 := Ax + Ay + 8.001598428:
eq2 := Bx + 20.08373119:
eq3 := By + Ay + 8.085329620:
eq4 := By + 0.315:
solutions := solve([eq1=0, eq2=0, eq3=0, eq4=0]);
{Ax = -0.2312688080, Ay = -7.770329620, Bx = -20.08373119,
By = -0.3150000000}
eval(Ax, solutions);
-0.2312688080
eval(Ax^2 + sin(By), solutions);
-0.2563312096
eq5 := cos(Bx) + sin(Ax); # still convenient
cos(Bx) + sin(Ax)
restart:
eq1 := Ax + Ay + 8.001598428:
eq2 := Bx + 20.08373119:
eq3 := By + Ay + 8.085329620:
eq4 := By + 0.315:
solutions := solve([eq1=0, eq2=0, eq3=0, eq4=0]);
{Ax = -0.2312688080, Ay = -7.770329620, Bx = -20.08373119,
By = -0.3150000000}
assign(solutions);
Ax;
-0.2312688080
Ax^2 + sin(By);
-0.2563312096
eq5 := cos(Bx) + sin(Ax); # oops
0.1010869460
unassign('Ax'):
unassign('Bx'):
eq5 := cos(Bx) + sin(Ax);
cos(Bx) + sin(Ax)