In order to solve an indefinite integral, I came with a solution which was not in accordance with the the book's solution. In order to check my solution, I tried to solve the problem using this code:
syms x
question=int(1/(x*(1+x^5)^0.5))`
mysolution=(1/5)*(log(((sqrt(1+x^5))-1)/(sqrt(1+x^5)+1)))
x=3
eval(question)
eval(mysolution)
Which resulted in:
ans =-0.0256 - 0.6283i
ans =-0.0256
I have to find the solution of an indefinite integral but when I gave MATLAB this problem (solving the indefinite integral) it gave another solution. In order to check whether my solution was right, I gave x
the value 3 using syms
and eval
, so MATLAB was supposed to show my answer and his own answer with the assumption of x=3
.
The real part of MATLAB's answer was the same as my answer but it it contained an imaginary part which was not in accordance with my solution. In fact, my answer with x=3
did not contain any imaginary part. what is wrong and Why is that so?
This is more a math question than a programming question.
Your indefinite integral can be written as:
which is equal to your solution, since
Now if we look at what Matlab is calculating, it says
This makes sense because
Now let's consider the imaginary part of matlab's solution: Let us recall that
ln
is not uniquely defined on the complex numbers, but has different branches. This is because the complex exponential function is2*pi*i
periodic:This is the imaginary part of a "multivalued" representation of a complex logarithm that visualizes this circumstance, you could say
So if we go back to your concrete example: The imaginary part was
- 0.6283
and you hadAnd guess what:
-1/5*pi*i = - 0.6283i
So this comes fromt he fact that Matlab is basically trying to find the logarithm of a negative value, hence the imaginary part
-pi*i
.So the lesson here: Be careful with complex numbers :D (or be careful with matlab's symbolic math routines...)