Sagemath:SyntaxError:关键字可以是表达式
最后,我想替换qij^2 = qij
,i,j = 1,2,3,4
并得到错误:
SyntaxError: keyword can't be an expression
代码:
sage: f1 = 2*x1 + x2 + 1
sage: f2 = -x1 + 5*x2 - 2
sage: e1 = expand(f1^2)
sage: e2 = expand(f2^2)
sage: var('q11, q12, q13, q14, q21, q22, q23, q24')
(q11, q12, q13, q14, q21, q22, q23, q24)
sage: E1 = e1.substitute(x1=q11+(2q12)-q13-(2q14), x2=q21+(2q22)-q23-(2q24))
sage: E2 = e2.substitute(x1=q11+(2q12)-q13-(2q14), x2=q21+(2q22)-q23-(2q24))
sage: E1a = expand(E1)
sage: E2a = expand(E2)
sage: E1aa = E1a.substitute(q11^2=q11, q12^2=q12, q13^2=q13, q14^2=q14,
....: q21^2=q21, q22^2=q22, q23^2=q23, q24^2=q24)
sage: E2aa = E2a.substitute(q11^2=q11, q12^2=q12, q13^2=q13, q14^2=q14,
....: q21^2=q21, q22^2=q22, q23^2=q23, q24^2=q24)
sage: E1aa, E2aa
At the end I wanted to substitute qij^2=qij
, i,j=1,2,3,4
and got the error:
SyntaxError: keyword can't be an expression
The code:
sage: f1 = 2*x1 + x2 + 1
sage: f2 = -x1 + 5*x2 - 2
sage: e1 = expand(f1^2)
sage: e2 = expand(f2^2)
sage: var('q11, q12, q13, q14, q21, q22, q23, q24')
(q11, q12, q13, q14, q21, q22, q23, q24)
sage: E1 = e1.substitute(x1=q11+(2q12)-q13-(2q14), x2=q21+(2q22)-q23-(2q24))
sage: E2 = e2.substitute(x1=q11+(2q12)-q13-(2q14), x2=q21+(2q22)-q23-(2q24))
sage: E1a = expand(E1)
sage: E2a = expand(E2)
sage: E1aa = E1a.substitute(q11^2=q11, q12^2=q12, q13^2=q13, q14^2=q14,
....: q21^2=q21, q22^2=q22, q23^2=q23, q24^2=q24)
sage: E2aa = E2a.substitute(q11^2=q11, q12^2=q12, q13^2=q13, q14^2=q14,
....: q21^2=q21, q22^2=q22, q23^2=q23, q24^2=q24)
sage: E1aa, E2aa
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只想替换一个变量,则可以使用
=
语法:e1a.substitute(q11 =(whywather))
。但是,如果您想代替更复杂的表达式,则需要使用其他语法:e1a.substitute产生的帮助消息?
提供了一些示例。If you want to just substitute for a variable, you can use the
=
syntax:E1a.substitute(q11=(whatever))
. If, though, you want to substitute for a more complicated expression, you need to use a different syntax:The help message produced by
E1a.substitute?
gives some examples.