# How to integrate this cumbersome piece-wise function?

I have this systems of equation:

kt = Sqrt[h/(π (y1 - y2))]*Integrate[p[y]*Sqrt[(1 + y)/(1 - y)], {y, -1, 1}]
kb = Sqrt[h/(π (y1 - y2))]*Integrate[p[y]*Sqrt[(1 - y)/(1 + y)], {y, -1, 1}]


In which: y1 and y2 are two variables that I need to find, -1<y2<0, 0<y1<1, and y1 and y2 are real.

The problem is that p[y] is a piece-wise function and is defined by:

p[y] := Piecewise[{
{p + a*(y1 + y2)/2 - a*2 h y/(y1 - y2) - t1, y2 < y < y1},
{p + a*(y1 + y2)/2 - a*2 h y/(y1 - y2) - t2, y1 < y < 1},
{p + a*(y1 + y2)/2 - a*2 h y/(y1 - y2) - t3, -1 < y < y2}}]


In which: a, p, t1, t2, t3, h are constants.

I need to find y1 and y2 so that:

kt==c1&&kb==c2


where c1 and c2 are two constants.

I had tried to solve this integration manually and the answer was lengthy and involved the inverse trigonometric equations. I also tried to use Solve, NSolve, Reduce, FindInstance and NIntegrate but Mathematica usually hangs. Since I have to solve this system of equations repeatedly, I really want to know how can I perform these calculations in Mathematica automatically?

• You need an underscore to define a function, like p[y_]. Aug 24 '13 at 7:45

You have certain assumptions regarding the values of y1 and y2 but you have not told Mathematica about them. If you provide these assumptions to Integrate, the symbolic integration proceeds smoothly (taking a couple of minutes):

kt = Sqrt[h/(π (y1 - y2))] Integrate[p[y] Sqrt[(1 + y)/(1 - y)], {y, -1, 1},
Assumptions -> {0 < y1 < 1, -1 < y2 < 0}];

kb = Sqrt[h/(π (y1 - y2))] Integrate[p[y] Sqrt[(1 - y)/(1 + y)], {y, -1, 1},
Assumptions -> {0 < y1 < 1, -1 < y2 < 0}];


You can then supply values for the parameters and get a result using FindRoot:

Block[{a = 1, p = 2, t1 = 3, t2 = 4, t3 = 5, h = 6, c1 = -30, c2 = 15},
FindRoot[{kt == c1, kb == c2}, {y2, -0.5}, {y1, 0.5}]]

(* {y2 -> -0.245106, y1 -> 0.801993} *)

• :It works. But, could you explain the elegant idea of specifying the domains of y1 and y2? I still don't get it. And why do you instruct Mathematica to start seeking solutions near the point {-0.5,0.5}? Is there any specific reason for this? Aug 24 '13 at 23:03
• @ThanhSon, well if you were doing the integral by hand you would probably split it into integrals from -1 to y2, y2 to y1 and y1 to 1, using the appropriate part of p[y] for each one. You can only do this if you know that -1 < y2 < y1 < 1. I expect Mathematica makes use of the information in a similar way. FindRoot needs a starting value for each parameter, so I just chose the middle of the domain for each. You can also tell FindRoot the domain of each parameter like {y2, -0.5, -1, 0} but it didn't seem necessary for this case. Aug 25 '13 at 9:23