问题
I am using xmaxima to solve two simultaneous non-linear equations using the 'solve' command.The answer displayed is x=[ans1, ans2,..], y=[ans1,ans2,...], But it is'int getting stored onto the variable 'x' and 'y' . How do I assign the output to a variable so that I can use the output for further calculations. The xmaxima code is as below:
A:0.500000000000000$
B:0.709506070053745$
C:0.242527534593605$
D:0.719012140107490$
E: 0.357164044380080$
F:-0.505315948652670$
G:0.181895650945204$
H: 0.300000000000000$
[x,y]=solve([x^2*(A*y^3+B*y-C)-D*x*y^2+E*y^3,A*x^2+(x/y^2)*(H*y+G)+F],[x,y]),numer;
output is:
[x, y] = [[x = 0.0611142802814223, y = 0.167915465898175],
[x = - 6.026109660574413, y = 0.305609155632444],
[x = 0.290917101108745, y = 0.445210848095313],
[x = 0.456144541234576 %i + 1.180400965797426,
y = 0.869595022612534 %i + 0.051360830266336],
[x = 1.180400965797425 - 0.456144541234575 %i,
y = 0.051360830266336 - 0.869595022612534 %i],
[x = 0.0609759975012744 %i - 0.777728688525087,
y = 0.792517145089706 %i - 0.51072855430292],
[x = - 0.0609759975012744 %i - 0.777728688525087,
y = - 0.792517145089706 %i - 0.51072855430292],
[x = 0, y = 0]]
回答1:
Firstly, note that there is more than one solution, so you have to decide what you want to do with them. One option is the following:
(%i9) solutions: solve([x^2*(A*y^3+B*y-C)-D*x*y^2+E*y^3,A*x^2+(x/y^2)*(H*y+G)+F],[x,y]), numer$
<snipped some info lines from rat>
(%i10) xvals: map(rhs, map(first, solutions));
(%o10) [.06111426947129051, - 6.026109660574413, .2909171173159695,
.4561445354339108 %i + 1.180400961416986,
1.180400961416985 - .4561445354339104 %i,
.06097600174281474 %i - 0.77772869099467,
- .06097600174281463 %i - 0.77772869099467, 0]
(%i11) yvals: map(rhs, map(second, solutions));
(%o11) [.1679154401926679, .3056091599125177, .4452108480953128,
.8695950265919334 %i + .05136082885038127,
.05136082885038127 - .8695950265919334 %i,
0.792517152411182 %i - .5107285531053073,
- 0.792517152411182 %i - .5107285531053073, 0]
Then you can get hold of the x,y pair for a solution via xvals[k]
and yvals[k]
(where you choose k between 1 and 8).
来源:https://stackoverflow.com/questions/9765715/how-to-assign-the-output-of-solve-in-maxima-to-a-variable