tags:

views:

141

answers:

2

Hi all, 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. My results are:

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'd much appreciate it!

If it helps any, I'm running Mathematica 7 on Windows 7 64-bit.

+2  A: 

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}}
Scott Morrison
Well, the first one certainly works. I get the proper result of A = sqrt(1/2). Only issue now, is as you say, doing the replacement of symbolic A with the result. I tried your second snippet, and that unfortunately won't work.
Sagekilla
Spoke too soon there, re-opened and re-evaluated all the expressions and the second may work.
Sagekilla
+2  A: 

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]}}
Janus
Great, thank! I'd forgotten about ToRules.
Scott Morrison