# \[?\] Solve an ODE with DSolve?

**URL:** <https://community.wolfram.com/t/solve-an-ode-with-dsolve/11159>\
**Category:** Questions\
**Tags:** equation-solving, symbolic-computations\
**Created:** [August 28, 2017, 11:22pm UTC](https://community.wolfram.com/t/solve-an-ode-with-dsolve/11159 "2017-08-28T23:22:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![michaeldd0](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@michaeldd0](https://community.wolfram.com/u/michaeldd0)\
**Post date:** [August 28, 2017, 11:22pm UTC](https://community.wolfram.com/t/solve-an-ode-with-dsolve/11159/1 "2017-08-28T23:22:14Z")

</div>

Hi, I’m new to Mathematica, and I’m trying to solve an ODE with it,  
but I get the wrong solution! (or maybe my book is wrong I dunno lol)

Here is the problem:

 ![ScreenShot2017-08-29at2.14.01.png](https://global.discourse-cdn.com/wolfram/original/3X/b/8/b85e6bcf9fe106440ec346483df40027bf89c26b.png)

and this should be the solution by my book:

 ![ScreenShot2017-08-29at2.14.45.png](https://global.discourse-cdn.com/wolfram/original/2X/9/9f9a676b49c07bc115b28eff8d332614f8e10716.png)

Now in Mathematica the code i used is:

```
DSolve[{x^2 * y''[x] + 7*x*y'[x] + 9*y[x] == 0, y'[-1] == -3, 
  y[-1] == 2}, y[x], x]

```

and the output is:  
{{y[x] → (I (2 I + 9 [Pi] + 9 I Log[x]))/x^3}}

image:

 ![ScreenShot2017-08-29at2.19.16.png](https://global.discourse-cdn.com/wolfram/original/3X/e/b/eb79e8e077632324fc395f4fb9ad65f709d84e2b.png)

What I’m doing wrong?

Thanks.

---

<div class="post-metadata">

**Author:** ![kayh](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/kayh/32/31501_2.png) [@kayh](https://community.wolfram.com/u/kayh)\
**Post date:** [August 29, 2017, 12:36am UTC](https://community.wolfram.com/t/solve-an-ode-with-dsolve/11159/2 "2017-08-29T00:36:26Z")

</div>

In[14]:= ClearAll[“Global`\*”]

```
In[15]:= DSolve[{x^2*y''[x] + 7*x*y'[x] + 9*y[x] == 0, y'[-1] == -3, 
  y[-1] == 2}, y[x], x]

Out[15]= {{y[x] -> (I (2 I + 9 \[Pi] + 9 I Log[x]))/x^3}}

In[16]:= y[x_] := (I (2 I + 9 \[Pi] + 9 I Log[x]))/x^3

```

Perhaps you copied down the equation wrong? The solution seems correct:

```
In[17]:= x^2*y''[x] + 7*x*y'[x] + 9*y[x] == 0

Out[17]= x^2 (63/x^5 + (12 I (2 I + 9 \[Pi] + 9 I Log[x]))/x^5) + 
  7 x (-(9/x^4) - (3 I (2 I + 9 \[Pi] + 9 I Log[x]))/x^4) + (
  9 I (2 I + 9 \[Pi] + 9 I Log[x]))/x^3 == 0

In[18]:= Reduce[
 x^2 (63/x^5 + (12 I (2 I + 9 \[Pi] + 9 I Log[x]))/x^5) + 
   7 x (-(9/x^4) - (3 I (2 I + 9 \[Pi] + 9 I Log[x]))/x^4) + (
   9 I (2 I + 9 \[Pi] + 9 I Log[x]))/x^3 == 0]

Out[18]= True

```

---

<div class="post-metadata">

**Author:** ![kayh](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/kayh/32/31501_2.png) [@kayh](https://community.wolfram.com/u/kayh)\
**Post date:** [August 29, 2017, 12:44am UTC](https://community.wolfram.com/t/solve-an-ode-with-dsolve/11159/3 "2017-08-29T00:44:32Z")

</div>

It could also be your boundary conditions:

```
In[28]:= ClearAll["Global`*"]

In[29]:= DSolve[{x^2*y''[x] + 7*x*y'[x] + 9*y[x] == 0, 
  y'[-1] == -9 - 3 I (2 I - 9 \[Pi]), y[-1] == -I (2 I - 9 \[Pi])}, 
 y[x], x]

Out[29]= {{y[x] -> (-2 - 9 Log[x])/x^3}}

In[33]:= y[-1]

Out[33]= -I (2 I - 9 \[Pi])

In[34]:= y'[-1]

Out[34]= -9 - 3 I (2 I - 9 \[Pi])

```

---

<div class="post-metadata">

**Author:** ![mroge02](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mroge02/32/28775_2.png) [@mroge02](https://community.wolfram.com/u/mroge02)\
**Post date:** [August 29, 2017, 1:10am UTC](https://community.wolfram.com/t/solve-an-ode-with-dsolve/11159/4 "2017-08-29T01:10:52Z")

</div>

The solutions are equivalent:

```
Simplify[(I (2 I + 9 ? + 9 I Log[x]))/x^3 - (-2 x^-3 - 9 x^-3 Log@Abs[x]), x < 0]
(* 0 *)

```

---

<div class="post-metadata">

**Author:** ![michaeldd0](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@michaeldd0](https://community.wolfram.com/u/michaeldd0)\
**Post date:** [August 29, 2017, 7:33am UTC](https://community.wolfram.com/t/solve-an-ode-with-dsolve/11159/5 "2017-08-29T07:33:09Z")

</div>

Yea right it is equal 🙂  
but how that’s possible.. I don’t see how: (9?i\*x^-3) have anything to do here?

---

<div class="post-metadata">

**Author:** ![anon21378091](https://avatars.discourse-cdn.com/v4/letter/a/bcef8e/32.png) [@anon21378091](https://community.wolfram.com/u/anon21378091)\
**Post date:** [August 29, 2017, 12:35pm UTC](https://community.wolfram.com/t/solve-an-ode-with-dsolve/11159/6 "2017-08-29T12:35:24Z")

</div>

Hi,

Keep in mind that `Log[]` is the complex logarithm:

```
Simplify[ComplexExpand@Log[x], x < 0]
(* 1/2 (2 I ? + Log[x^2]) *)

Log[-1]
(* I ? *)

(* etc. *)

```

Because your initial condition is at `x == -1`, the `Log[x]` in the solution returned by `DSolve` has a nonzero imaginary part, namely, `I ?`. You can somewhat recover the desired form of the answer as follows:

```
Simplify[(I (2 I + 9 ? + 9 I Log[x]))/x^3, x < 0]
(* (-2 - 9 Log[-x])/x^3 *)

```

It is, in fact, a strength that Mathematica works in terms of complex analysis, but OTOH, most people haven’t studied complex analysis. From the point of view of mathematics through the first two years of college calculus (= introductory real analysis), it can seem unnecessarily complex – i.e., complicated. 🙂 – to both students and professors. Recently, as Wolfram has made inroads into the introductory math curriculum and, reciprocally, interest in Wolfram has grown, functions such as `CubeRoot[]` (V9), `Surd[]` (V9), and `RealAbs[]` (V11.1) have been introduced, which are the standard real functions studied in high school.

---

<div class="post-metadata">

**Author:** ![mariuszi28cg](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mariuszi28cg/32/308_2.png) [@mariuszi28cg](https://community.wolfram.com/u/mariuszi28cg)\
**Post date:** [August 29, 2017, 12:53pm UTC](https://community.wolfram.com/t/solve-an-ode-with-dsolve/11159/7 "2017-08-29T12:53:28Z")

</div>

`DSolve[]` always treats all variables as complex; unless you tell, say, `FullSimplify[]` that `x` is real.

```
 sol = y[x] /. First@DSolve[{x^2*y''[x] + 7*x*y'[x] + 9*y[x] == 0, y'[-1] == -3, y[-1] == 2}, y[x], x]
 FullSimplify[Re[sol] // ComplexExpand, Assumptions -> x > 0] // Expand

```

y(x)=-\frac{2}{x^3}-\frac{9 \log (x)}{x^3}

---

<div class="post-metadata">

**Author:** ![mroge02](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mroge02/32/28775_2.png) [@mroge02](https://community.wolfram.com/u/mroge02)\
**Post date:** [August 29, 2017, 4:45pm UTC](https://community.wolfram.com/t/solve-an-ode-with-dsolve/11159/8 "2017-08-29T16:45:06Z")

</div>

I think there’s a slight mistake: (1) The initial condition is at a negative value of x, so the domain of the solution is x \< 0. (2) The solution is real so `Re` in `Re[sol]` should be unnecessary. (3) Consequently, the assumption in `FullSimplify` leads to an expression that has a nonzero imaginary part at x = -1 due to log(x), and the initial condition is not satisfied.

---

<div class="post-metadata">

**Author:** ![mariuszi28cg](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/mariuszi28cg/32/308_2.png) [@mariuszi28cg](https://community.wolfram.com/u/mariuszi28cg)\
**Post date:** [August 30, 2017, 9:19am UTC](https://community.wolfram.com/t/solve-an-ode-with-dsolve/11159/9 "2017-08-30T09:19:37Z")

</div>

Hello

You are absolutely right ,I do not check initial condition for solution.

My mistake.

Regards Mariusz.
