如何在 maxima 中访问数组中的特定元素?
使用求解命令求解两个联立非线性方程后,我得到一个 x 和 y 数组,我需要访问该数组中的特定元素。
A: 0.500000000000000$
B: 0.709506070053745$
C: 0.242527534593605$
D: 0.719012140107490$
E: 0.357164044380080$
F:-0.505315948652670$
G: 0.181895650945204$
H: 0.300000000000000$
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;
这里,x
和 y
各包含 8 个值,我只需要访问第二个元素。
After using the solve command to solve two simultaneous non linear equations, I am getting an array of x
and y
and I need to access specific elements in this array.
A: 0.500000000000000$
B: 0.709506070053745$
C: 0.242527534593605$
D: 0.719012140107490$
E: 0.357164044380080$
F:-0.505315948652670$
G: 0.181895650945204$
H: 0.300000000000000$
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;
Here, x
and y
contain 8 values each and I need to access say only the 2nd element.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Maxima 在这里返回结果列表(maxima 数组略有不同)。列表中的每个元素都是一对方程(x = ... 和 y = ...)。对于阅读本文的其他人来说,结果看起来像
现在,我不确定您的问题是否只需要每个 y 坐标,或者您是否想要找到解决方案的第二个解决方案。对于第二种解决方案,只需使用
[n]
即可获取第 n 个东西。因此,如果我将上面的列表存储为变量solns
,我可以使用如果您想要每个
y
坐标,则必须映射到列表中。例如,试试这个:(我稍微整理了输出的格式)。或者您也可以同样
给出完全相同的答案,但不需要编写 lambda 形式。
Maxima returns a list of results here (a maxima array is something slightly different). Each element of the list is a pair of equations (x = ... and y = ...). For others reading this, the results look like
Now, I'm not sure from your question whether you want just each
y
coordinate, or whether you want the second solution that solve found. For the second solution, just use[n]
to get the n'th thing. So if I stored the list above as the variablesolns
, I could useIf you want each
y
coordinate, you have to map into the list. For example, try this:(I tidied up the formatting of the output slightly). Or you could equally do
which gives exactly the same answer but without needing to write a lambda form.