Mathematica:使用 Solve 时提取数值
在 Mathematica 中,调用 Solve
会返回规则列表,例如,
In[1]:= g = Solve[(x - 1) (x - 2) == 0, x]
Out[1]= {{x -> 1}, {x -> 2}}
如何从 g 中提取数值
1
或 2
?
我尝试使用 Part
例如 g[[1]]
但它返回 {x -> 1}
而不是 1
。
请指教。
In Mathematica, calling Solve
, returns a list of rules, e.g.,
In[1]:= g = Solve[(x - 1) (x - 2) == 0, x]
Out[1]= {{x -> 1}, {x -> 2}}
How can I extract the numerical values 1
or 2
from g
?
I tried using Part
e.g., g[[1]]
but it returns {x -> 1}
and not 1
.
Please advise.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了补充贝利撒留的答案,
用
g = {{x -> 1},{x-> 2}}
,返回列表因此要提取第一个值,
1
,我们可以使用其他替代方案是
To complement Belisarius' answer,
with
g = {{x -> 1}, {x -> 2}}
, returns the listSo to extract the first value,
1
, we could useOther alternatives are
填料->最少三十个字符
Filler -> Thirty chars minimum