1
$\begingroup$

I am new to mathematica. Here is the question. I try to do the following integration with the assumption that k1<0, k2<0 and k1,k2 are real number. However, the result includes \sqrt{k1}?

Furthermore, in the result, the term e^{2h(s-T)}k1 - k2 could also be negative ? How I can do to prevent mathematica use log function?

enter image description here

$\endgroup$
  • 1
    $\begingroup$ reals must be capitalized. $\endgroup$ – Szabolcs Jan 21 '16 at 17:05
  • $\begingroup$ Change to capital letter, does not work either $\endgroup$ – J.J.Gao Jan 21 '16 at 17:12
  • 2
    $\begingroup$ Please post, properly formatted, copy-and-pastable code in code blocks rather than screenshots of code. Edit your post by clicking the grey edit button at the bottom of the post and click on the grey question mark on the right side of the editing toolbar for help with formatting. $\endgroup$ – march Jan 21 '16 at 17:20
  • $\begingroup$ Indefinite integration in Integrate makes no use of Assumptions. One might do Refine[Integrate[...], Assumptions->...]. Or use (Full)Simplify if Refine is not strong enough. $\endgroup$ – Daniel Lichtblau Jan 21 '16 at 23:14
3
$\begingroup$

The copyable code you omitted:

res = Integrate[(1 - Exp[h *(s - T)])^4/(k2 - k1* Exp[(s - T)*(2 h)])^2, s, 
  Assumptions -> Element[k1 | k2, Reals] && k1 < 0 && k2 < 0]

Mathematica graphics

You are surprised to see a term $\sqrt{k1}$ pop up in the answer, with k1 defined as being negative. You don't specify why you see that as a problem, so I have to guess. I presume that you feel it is a problem that you will end up with complex numbers in the integral of a function that itself is real, and indeed you get those if you fill in a few numbers:

res /. {k1 -> -1., k2 -> -2., t -> 0, s -> 1, h -> 1} 
(* 2.01401 + 0.0673765 I *)

What you forget is that you have an indefinite integral whose result is determined up to a constant of integration. Indeed, if you check a different value of s you get:

res /. {k1 -> -1., k2 -> -2., t -> 0, s -> 3, h -> 1} 
(* 3.18752 + 0.0673765 I *)

Subtract both values to get the definite integral and you see the imaginary terms will cancel.

About negative logs: No problem, Mathematica can deal easily with those, just as it handles square roots of negative values:

Log[-2]
(* I π + Log[2] *)
$\endgroup$
  • $\begingroup$ Thanks for the answer. Actually, I need the analytical expression of this integration in matlab. Mathematica is more robust to the thing like log(-1). $\endgroup$ – J.J.Gao Jan 22 '16 at 7:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.