# Integrating piecewise function on an range

P1 = Integrate[(Abs[\[Psi]s1])^2, {x, 0,b}]


When I integrate the above function, I am getting an answer as below. I am not sure what's going on. 1/3 a A Conjugate[A]

Psi]s1 is same as the following piecewise function. ie, [Psi]s1= [Psi][x, 0] I am expecting,

Then only further calculations can be performed.

Also while integrating the modulus square of the above piece wise functions , it is showing an error.

 \[Psi][x_, 0] :=
Piecewise[{{(A*x)/a, 0 <= x <= a}, {A*(b - x)/(b - a), a <= x <= b}}]
Integrate[(Abs[\[Psi][x, 0]])^2, {x, a, b}]


• You have not provided all of the definitions, e.g., what is \[Psi]s1? Oct 19, 2020 at 0:00
• Edited the question by including the definition. Oct 19, 2020 at 0:04

Clear["Global*"]


Include the assumption 0 < a < b

ψ[x_, 0] :=
Piecewise[{{(A*x)/a, 0 <= x <= a}, {A*(b - x)/(b - a), a <= x <= b}}]

Assuming[0 < a < b,
Integrate[(Abs[ψ[x, 0]])^2, {x, 0, b}] // Simplify]

(* 1/3 b Abs[A]^2 *)

Assuming[0 < a < b,
Integrate[(Abs[(A*x)/a])^2, {x, 0, a}] +
Integrate[(Abs[A*(b - x)/(b - a)])^2, {x, a, b}] // Simplify]

(* 1/3 b Abs[A]^2 *)

Assuming[0 < a < b,
Integrate[(Abs[ψ[x, 0]])^2, {x, 0, a}] +
Integrate[(Abs[ψ[x, 0]])^2, {x, a, b}] // Simplify]

(* 1/3 b Abs[A]^2 *)

• When I solve for the A, I am getting both positive and negative values. That means Abs is not working properly. This is because absolute value of a quantity shouldn't be negative! ie, A1 = Assuming[0 < a < b, Solve[ 1/3 b Abs[A]^2 == 1, Abs[A]]] Oct 19, 2020 at 0:34
• You are trying to use Abs[A] as if it were a variable. The Abs in that context doesn't get evaluated. You probably intend A1 = Assuming[0 < a < b, Solve[{1/3 b Abs[A]^2 == 1}, A]]` Oct 19, 2020 at 0:52
• Both are giving same results! But I understood your point Oct 19, 2020 at 0:55