如何在 maxima 中访问数组中的特定元素?

发布于 2025-01-01 03:25:26 字数 420 浏览 5 评论 0原文

使用求解命令求解两个联立非线性方程后,我得到一个 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;

这里,xy 各包含 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

被翻牌 2025-01-08 03:25:26

Maxima 在这里返回结果列表(maxima 数组略有不同)。列表中的每个元素都是一对方程(x = ... 和 y = ...)。对于阅读本文的其他人来说,结果看起来像

 [[x = .06111426947129051, y = .1679154401926679], 
  [x = - 6.026109660574413, y = .3056091599125177], 
  [x = .2909171173159695, y = .4452108480953128], 
  [x = .4561445354339108 %i + 1.180400961416986, 
   y = .8695950265919334 %i + .05136082885038127], 
  [x = 1.180400961416985 - .4561445354339104 %i, 
   y = .05136082885038127 - .8695950265919334 %i], 
  [x = .06097600174281474 %i - 0.77772869099467, 
   y = 0.792517152411182 %i - .5107285531053073], 
  [x = - .06097600174281463 %i - 0.77772869099467, 
   y = - 0.792517152411182 %i - .5107285531053073],
  [x = 0, y = 0]]

现在,我不确定您的问题是否只需要每个 y 坐标,或者您是否想要找到解决方案的第二个解决方案。对于第二种解决方案,只需使用 [n] 即可获取第 n 个东西。因此,如果我将上面的列表存储为变量 solns,我可以使用

(%i12) solns[2];
(%o12)         [x = - 6.026109660574413, y = .3056091599125177]

如果您想要每个 y 坐标,则必须映射到列表中。例如,试试这个:(

(%i14) map(lambda([pair], rhs(second(pair))), solns);
(%o14) [.1679154401926679,
        .3056091599125177,
        .4452108480953128, 
        .8695950265919334 %i + .05136082885038127,
        .05136082885038127 - .8695950265919334 %i, 
        0.792517152411182 %i - .5107285531053073, 
        - 0.792517152411182 %i - .5107285531053073,
        0]

我稍微整理了输出的格式)。或者您也可以同样

map(rhs, map(second, solns));

给出完全相同的答案,但不需要编写 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

 [[x = .06111426947129051, y = .1679154401926679], 
  [x = - 6.026109660574413, y = .3056091599125177], 
  [x = .2909171173159695, y = .4452108480953128], 
  [x = .4561445354339108 %i + 1.180400961416986, 
   y = .8695950265919334 %i + .05136082885038127], 
  [x = 1.180400961416985 - .4561445354339104 %i, 
   y = .05136082885038127 - .8695950265919334 %i], 
  [x = .06097600174281474 %i - 0.77772869099467, 
   y = 0.792517152411182 %i - .5107285531053073], 
  [x = - .06097600174281463 %i - 0.77772869099467, 
   y = - 0.792517152411182 %i - .5107285531053073],
  [x = 0, y = 0]]

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 variable solns, I could use

(%i12) solns[2];
(%o12)         [x = - 6.026109660574413, y = .3056091599125177]

If you want each y coordinate, you have to map into the list. For example, try this:

(%i14) map(lambda([pair], rhs(second(pair))), solns);
(%o14) [.1679154401926679,
        .3056091599125177,
        .4452108480953128, 
        .8695950265919334 %i + .05136082885038127,
        .05136082885038127 - .8695950265919334 %i, 
        0.792517152411182 %i - .5107285531053073, 
        - 0.792517152411182 %i - .5107285531053073,
        0]

(I tidied up the formatting of the output slightly). Or you could equally do

map(rhs, map(second, solns));

which gives exactly the same answer but without needing to write a lambda form.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文