# Find $f$ if $f'(x)=\dfrac{x^2-1}{x}$ knowing that $f(1) = \dfrac{1}{2}$ and $f(-1) = 0$

I am asked the following problem:

Find $f$ if $$f'(x)=\frac{x^2-1}{x}$$

I am not sure about my solution, which I will describe below:

My solution:

The first thing that I've done is separate the terms of $f'(x)$

\begin{align*} f'(x)&=\frac{x^2-1}{x}\\ &=x-\frac{1}{x}\\ \therefore \quad f(x)&=\frac{x^2}{2}-\ln|x|+c \end{align*}

For ( x > 0 ):

\begin{align*} f(x)&=\frac{x^2}{2}-\ln x+c\\ f(1)&=\frac{1^2}{2}-\ln 1+c=\frac{1}{2} \quad \Rightarrow \quad c=0\\ f(x)&=\frac{x^2}{2}-\ln |x| \end{align*}

For ( x < 0 )

\begin{align*} f(x)&=\frac{x^2}{2}-\ln (-x)+c\\ f(-1)&=\frac{(-1)^2}{2}-\ln [-(-1)]+c=0 \quad \Rightarrow \quad c=-\frac{1}{2}\\ f(x)&=\frac{x^2}{2}-\ln |x|-\frac{1}{2} \end{align*}

Is my solution correct? Should I really find two different answers, one for $x > 0$ and another for $x < 0$?

Thank you.

• yes your solution is fine. As the domain has two connected components there can indeed be different constants of integration on each of them. – H. H. Rugh Sep 25 '16 at 17:03
• It looks fine to me. +1 – DonAntonio Sep 25 '16 at 17:03
• Related: math.stackexchange.com/questions/234624/… (see the accepted answer) – Winther Sep 26 '16 at 1:18

Looks fine! However a little typo when calculate $f(-1)=0$ not $-1$