40

22

I'm trying to expedite some quantum mechanical calculations (expectation values etc.) by running them through *Mathematica*. When I say, for example,

```
u[x_] := Sqrt[2/L] * Sin[Pi * n * x / L]
```

and then take the complex conjugate, I get

```
Sqrt[2] Conjugate[Sqrt[1/L]] Sin[(π Conjugate[n x])/Conjugate[L]]
```

But I want to tell *Mathematica* that some of the parameters are real (i.e. $L$) and some are integer valued and real (i.e. $n$). Is there a way to do that? I've tried adapting some syntax that I've seen in other context (but do not strictly know what it means or does) but it hasn't worked. For example,

```
Conjugate[u[x], Im[n] = 0]
Sin[n*Pi] /. n = Integer
```

Don't work the way I want them to. Chugging through this, however, when it comes time to compute values (like, in this example, $\langle p^2\rangle$, I get the following:

```
Integrate[u[x]*(-h^2)*u''[x], {x, 0, L}]
(* => (h^2 n π (n π - 1/2 Sin[2 n π]))/L^2 *)
```

where the second term there is clearly zero for all integer values of $n$ (but *Mathematica* doesn't know that).

3

`But I want to tell Mathematica that some of the parameters are real (ie L) and some are integer valued`

you can us e`ComplexExpand`

it says`expands expr assuming that all variables are real`

, for integers, you can use`Assuming[Element[x,Integers],Simplify[....]]`

– Nasser – 2014-11-21T22:54:38.6805

There's no general way to declare a variable as real, integer etc. Instead, some functions take an

– Szabolcs – 2014-11-21T22:56:53.893`Assumptions`

option which affects that function. Take a look at http://reference.wolfram.com/language/tutorial/UsingAssumptions.html and also`ComplexExpand`

. There can be a default for the`Assumptions`

option through`$Assumptions`

but it won't affect everything, only functions that know about assumptions.