在 Mathematica 中求正平方根

发布于 2024-09-03 10:10:00 字数 711 浏览 3 评论 0原文

我目前正在按照以下方式进行一些标准化:

J = Integrate[Psi[x, 0]^2, {x, 0, a}]
sol = Solve[J == 1, A]
A /. sol

对于这种类型的标准化,负平方根是无关的。这个计算的结果是:

In[49]:= J = Integrate[Psi[x, 0]^2, {x, 0, a}]
Out[49]= 2 A^2

In[68]:= sol = Solve[J == 1, A]
Out[68]= {{A -> -(1/Sqrt[2])}, {A -> 1/Sqrt[2]}}

即使我尝试给它一个 Assuming[...] 或 Simplify[...],它仍然给我相同的结果:

In[69]:= sol =  Assuming[A > 0, Solve[J == 1, A]]
Out[69]= {{A -> -(1/Sqrt[2])}, {A -> 1/Sqrt[2]}}

In[70]:= sol =  FullSimplify[Solve[J == 1, A], A > 0]
Out[70]= {{A -> -(1/Sqrt[2])}, {A -> 1/Sqrt[2]}}

谁能告诉我我在这里做错了什么?

我在 Windows 7 64 位上运行 Mathematica 7。

I'm currently doing some normalization along the lines of:

J = Integrate[Psi[x, 0]^2, {x, 0, a}]
sol = Solve[J == 1, A]
A /. sol

For this type of normalization, the negative square root is extraneous. The result of this calculation is:

In[49]:= J = Integrate[Psi[x, 0]^2, {x, 0, a}]
Out[49]= 2 A^2

In[68]:= sol = Solve[J == 1, A]
Out[68]= {{A -> -(1/Sqrt[2])}, {A -> 1/Sqrt[2]}}

Even if I try giving it an Assuming[...] or Simplify[...], it still gives me the same results:

In[69]:= sol =  Assuming[A > 0, Solve[J == 1, A]]
Out[69]= {{A -> -(1/Sqrt[2])}, {A -> 1/Sqrt[2]}}

In[70]:= sol =  FullSimplify[Solve[J == 1, A], A > 0]
Out[70]= {{A -> -(1/Sqrt[2])}, {A -> 1/Sqrt[2]}}

Can anyone tell me what I'm doing wrong here?

I'm running Mathematica 7 on Windows 7 64-bit.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

一场信仰旅途 2024-09-10 10:10:00

ToRules 执行框内显示的操作:将方程(如 Reduce 输出)转换为规则。对于您的情况:

In[1]:= ToRules[Reduce[{x^2==1,x>0},x]]
Out[1]= {x->1}

In[2]:= {ToRules[Reduce[{x^2==1},x]]}
Out[2]= {{x->-1},{x->1}}  

对于更复杂的情况,我经常发现在插入典型参数值后检查符号解的值很有用。当然,这并不是万无一失的,但如果您知道只有一个解决方案,那么这是一种简单而有效的方法:

Solve[x^2==someparameter,x]
Select[%,((x/.#)/.{someparameter-> 0.1})>0&]

Out[3]= {{x->-Sqrt[someparameter]},{x->Sqrt[someparameter]}}
Out[4]= {{x->Sqrt[someparameter]}}

ToRules does what the box says: converts equations (as in Reduce output) to rules. In your case:

In[1]:= ToRules[Reduce[{x^2==1,x>0},x]]
Out[1]= {x->1}

In[2]:= {ToRules[Reduce[{x^2==1},x]]}
Out[2]= {{x->-1},{x->1}}  

For more complex cases, I have often found it useful to just check the value of the symbolic solutions after pluging in typical parameter values. This is not foolproof, of course, but if you know there is one and only one solution then it is a simple and efficient method:

Solve[x^2==someparameter,x]
Select[%,((x/.#)/.{someparameter-> 0.1})>0&]

Out[3]= {{x->-Sqrt[someparameter]},{x->Sqrt[someparameter]}}
Out[4]= {{x->Sqrt[someparameter]}}
长发绾君心 2024-09-10 10:10:00

Solve 不是这样工作的。您可以尝试使用Reduce,例如,

In[1]:= Reduce[{x^2 == 1, x > 0}, x]
Out[1]= x == 1

至少在一般情况下,将此输出转换为替换规则会有点棘手,因为Reduce可能使用任意多个逻辑连接词。在这种情况下,我们可以破解:

In[2]:= Solve[Reduce[{x^2 == 1, x > 0}, x], x]
Out[2]= {{x->1}}

Solve doesn't work like this. You might try Reduce, instead, e.g.

In[1]:= Reduce[{x^2 == 1, x > 0}, x]
Out[1]= x == 1

It's then a little tricky to transform this output to replacement rules, at least in the general case, because Reduce might use arbitrary many logical connectives. In this case, we could just hack:

In[2]:= Solve[Reduce[{x^2 == 1, x > 0}, x], x]
Out[2]= {{x->1}}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文