# Nonlinear First order ODE: dy/dx = x + y^2

toneboy1

## Homework Statement

I want to find the general solution for y(x) if dy/dx = x + y^2 with initial cond't y(1) = 2

## The Attempt at a Solution

I can't figure out how to make it linear. (Obviously I don't think it's seperable)

Any suggestions/solutions?
Thanks very much!

Homework Helper
toneboy1
Thanks for the repsonse. I've been looking into this all day but still not understanding it.
Specifically I don't see how in your link they got from (4) to (6).

But more puzzlingly I looked here: (you probably dont need to check)
http://www.sosmath.com/diffeq/first/riccati/riccati.html

Please humour me if it's like the chain rule or something, but I don't see it.

I couldn't find one single youtube video to explain any of this!

Thanks,

#### Attachments

• img4.gif
11.6 KB · Views: 766
Last edited:
Homework Helper
Yours is of form: y'=axn+by2 where a=b=n=1.

If we use form (4) then:

y' = P(x)+Q(x)y+R(x)y2 where P=x, Q=0, and R=1.

we'd substitute: y=-z'/z ans y'=(z'/z)'

hint: quotient rule - careful to keep track of that minus sign ;)

according to (6) that gives z''+xz=0

toneboy1
Sorry, I still don't understand where y = -z'/z came from. (?) But differentiating it I got y' = -2z''/z ...? If that's right what was it equated to, to yeald z'' +xz = 0?

So I (4) (5) and (6) are still yet to make sense to me.

If you looked at that picture I attached, could you tell me, was y = 2 + 1/z ; y' = z'/z^2 some chain rule?

Thanks!!

Homework Helper
Sorry, I still don't understand where y = -z'/z came from.
The point of making a substitution is to turn a difficult DE into one we stand a chance to solve. It doesn't always work - there is a lot of trial and error in figuring out what kinds of substitutions to use for which kinds of equations.
what was it equated to, to yeald z'' +xz = 0
you don't equate it to anything, you substitute it into: y'=x+y2
differentiating it I got y' = -2z''/z
How?
The quotient rule is:
(f/g)'=(gf'-fg')/g2 put f=z' and g=z.

If you looked at that picture I attached, could you tell me, was y = 2 + 1/z ; y' = z'/z^2 some chain rule?
Yes. apply the sum rule, then the power rule. With the chain rule, the power rule looks like this:

(gn)' = ngn-1g' ... where g=z(x) and n=-1.

It can also be done via the quotient rule or, for that matter, the product rule.
It's called "implicit differentiation".
What level are you doing this at?

• ebdaaa55
toneboy1
Ah, that is an interesting premice.

I see. So why is f = z' and not f = -z' ?

Anyway, so solving for z = Ce^-x^2/2

Therefore y = (Ce^-x^2/2)' / Ce^-x^2/2 is that right?

Embarrassingly undergraduate level, but I haven't done anything like this for years.

I have a hard time seeing how y = 1/z could be done with the Quotent rule? (or product)

Thanks (very much) again!

Homework Helper
I see. So why is f = z' and not f = -z'
... same reason I don't do g=-z: avoids misplacing the "-" sign later.
I have a hard time seeing how y = 1/z could be done with the Quotent rule? (or product)
The quotient rule is a special case of the product rule with the power rule.

f/g = f.g-1 - now use product rule on RHS.

if y=1/z =f/g then f=1, f'=0, g=z, g'=z' ... now apply the quotient rule.

All this is usually covered in 1st year college pure math papers... but we all get rusty.
You should review basic differentiation to get back up to speed.

If we keep this up I'm going to have to teach you some LaTeX (which you will need if you do anything math-related next year anyway.)

Anyway, so solving for z = Ce^-x^2/2

Therefore y = (Ce^-x^2/2)' / Ce^-x^2/2 is that right?
... well, if the first line then the second ... however, what makes you think that $Ce^{-x^2/2}$ is a solution to $z^\prime +xz = 0$.

Since this is coursework - I'd be asking myself if my course has included this sort of thing: has it mentioned Riccati equations? Airy functions? Bessel equations?

Last edited:
toneboy1
Actually I'm not sure if this question was came up in the course or if I just wonedered it myself. I'm inclined to think the latter because I don't recall Airy functions, bessel equations or Riccati being said at anypoint. It was late and I was learning vector fields or 4th order Runge Kutta and I had it scribbled down the next day.

Sorry for the lack of clarity, I should have put brackets around the exponent.

Ah! LaTeX. I've seen that sort of code on the internet before, and I was like 'h'mm that doesn't look like matlab, I wonder what it is'. Thanks for giving me that lead to investigate.

Wow, I made a terrible algebraic mistake when I tried it, I have to do my working out neater. Thanks I'll remember I can cross-check my derivative answers with a different method next time I'm unsure.

I'll give more working out next time, so you can tell me where I'm wrong quicker and I dont waste as much of your time:
for z'' + xz = 0 μ = e^(Int[x]dx) = e^(x^2/2)

z.e^(x^2/2) = Int [0.e^(x^2/2)]

z.e^(x^2/2) = C

z = Ce^(-x^2/2)

That's how I got z (I'm assuming it's wrong). Finally, I phrased most of this terribly, I should have said how exactly is: y=-z'/z ans y'=(z'/z)' ?

Thank you * 10

however, what makes you think that $Ce^{-x^2/2}$ is a solution to $z^\prime +xz = 0$.

I know that was just a typo Simon as you previously had it correct , but that actually is a correct solution to that equation. The equation however was $z^{\prime \prime} +xz = 0$.

I'll give more working out next time, so you can tell me where I'm wrong quicker and I dont waste as much of your time:
for z'' + xz = 0

μ = e^(Int[x]dx) = e^(x^2/2)

z.e^(x^2/2) = Int [0.e^(x^2/2)]

z.e^(x^2/2) = C

z = Ce^(-x^2/2)
No, that's an "integrating factor" solution for the first order DE: $z^{\prime} +xz = 0$, not the 2nd order DE we're considering here.

Homework Helper
LaTeX is a typsetting script - defacto standard for academic papers.

Lets me write y=-z'/z => y'=-(z'/z)'=-z''/z + (z'/z)2 as
$$y=-\frac{z^\prime}{z} \Rightarrow y^\prime = -\left ( \frac{z^\prime}{z} \right )^\prime = -\frac{z^{\prime\prime}}{z}+\left ( \frac{z^\prime}{z}\right )^2$$... or, in Liebnitz notation:$$y=-\frac{1}{z}\frac{dz}{dx} \Rightarrow \frac{dy}{dx} = -\frac{d}{xd}\left ( \frac{1}{z}\frac{dz}{dx} \right ) = -\frac{1}{z}\frac{d^2z}{dx^2} + \left ( \frac{1}{z}\frac{dz}{dx} \right )^2$$

$z=Ce^{-x^2/2}$ cannot be the general solution to $\frac{d^2z}{dx^2}+xz=0$ because it only has one arbitrary constant - and the DE is second order.

It is, however, as you have calculated, the solution to $\frac{dz}{dx}+xz=0$ :)

The actual solution is $z(x)=c_1\text{Ai}(kx)+c_2\text{Bi}(kx): k^3=-1$ where the Ai and Bi are the Airy functions.

The solution to the 1st equation is a big mess of Bessel functions.

Considering your recent subject matter - perhaps you should try working out the specific solution you are after, with the given boundary conditions, numerically?

toneboy1
Thank you both for pointing that out, quite an over-sight on my part. I need a lot more practice. I'm assuming Power Series wouldn't work on
z'' + xz = 0 ?

I'm now not sure I could find a specific solution given the boundary conditions. It'd be something along the lines of:

y(x) = - (c1Ai(kx)+c2Bi(kx))' / c1Ai(kx)+c2Bi(kx) (which I don't understand)
with k^3 = -1 , y = 2 and x = 1 would it not?

(You must be so sick of me by now, don't worry, I've all but conceeded to let it go now)

Thanks.

Homework Helper
That wolfram link I gave you tells you what circumstances will give you a solution in terms of exponentials and powers and stuff like that - this is not one of them.

One of the things about 1st order non-linear is that it is easy to make them very nasty.
This is pretty scary and it is one of a class of DEs with known solutions. Lots have no analytic solutions at all.

Just y'=f(x,y) does not look all that tough until you realize that f(x,y) can be anything.
It's basically what computers are for.

You pretty much have to go look up these special functions.
They show up in models of nature quite a lot... so you do need to know about them.
Just not yet :D

toneboy1
Had I this new found understanding of how nasty this actually is it would have saved us both a lot of time. Nevertheless I won't soon forget any of this.

Thanks again!

Since the analytical solution was so horrible, here is a numerical solution to the problem. I used the following code in Matlab (or gnu Octave).

Code:
f = @(x,y) x+y.*y
opt = odeset("RelTol",1e-8,"AbsTol",1e-8,"MaxStep",4e-4,"InitialStep",4e-4)
[x,y] = ode45(f,[0,1.45],0.4805,opt);
plot(x,y)

- The value of y(0)=0.4805 was found by a "shooting" method to give y(1)=2
- The solution "blows up" at about x = 1.47, so I ended the simulation at x = 1.45

To help get some insight into the solution, and why it blows up like it does, consider the simplified separable equation $y' = y^2$, with y(1)=2. It is trivial to solve (by separation) and obtain:
$$y = \frac{1}{1.5-x}$$

It's interesting that although we changed the equation to completely omit the "$+x$" that the behavior near where it "blows up" is very similar, as the y^2 term completely dominates "x" here anyway. Obviously the simplified equation "blows up" at x = 1.5.

The attachments show the numerical solution of your equation and the solution of the simplified equation. (The first one is your equation and the second one the simplified separable one).

#### Attachments

Last edited:
toneboy1
Forgive my ignorance, I have a lot of it, but what is the difference between 'analytical' and 'numerical'? I was using them interchaingably.

I'm new to matlab but what does the '@(x,y)' i.e the '@' symbol in that context and 'odeset' command do? Or for that matter 'ode45'? (I still do understand the result of the code)

I did a 4th order Runge-Kutta and got a similar result.

when you solved y'' = y^2 ...well I am going wrong somewhere because I got:

∫∫1/y^2 dy = ∫∫dx

(ln y)/2 = x^2 / 2

I see your matlab code but no other attachments.

EDIT:

THey just came through

Forgive my ignorance, I have a lot of it, but what is the difference between 'analytical' and 'numerical'? I was using them interchaingably.
Analytically in this context literally mean "by analysis", rather than just plain dumb number crunching.

I'm new to matlab but what does the '@(x,y)' i.e the '@' symbol in that context and 'odeset' command do? Or for that matter 'ode45'? (I still do understand the result of the code)
@x() is called an "anonymous" function, it's kind of like an inline definition for simple functions. You can also define functions by writing them as ".m" files, which is the more regular way to do it.

ode45 is a 4th order runge kutta ode solver. odeset is a companion function to create a vector of options that ode45 needs (to set things like stepsize and tolerances). It will take default values if you don't use odeset, but for tricky equations like this it's best to manually set a small stepsize.

I did a 4th order Runge-Kutta and got a similar result.
Not surprising, as this was also a 4th order runge kutta. when you solved y'' = y^2 ...well I am going wrong somewhere because I got:

∫∫1/y^2 dy = ∫∫dx

(ln y)/2 = x^2 / 2...

No, $\int (1/y^2) dy$ is just $(-y^{-1} + C)$, it's not log().

Last edited:
Homework Helper
Putting it simply...
Analytic(al) solutions will give you the actual equation in a form where you can plug numbers in and get answers out the usual way - numerical solutions just give you a bunch of numbers.

The term "analytic" is also a technical term in philosophy - closely related.

toneboy1
Fancy that. That matlab info will be sure to come in useful.

No, $\int (1/y^2) dy$ is just $(-y^{-1} + C)$, it's not log().

Ah, yes.
But then don't you need to integrate it again, so it would become something like

∫∫(1/y^2) dy = - ln |y| + Cy + C1 (Those constants don't look right) ?

Ah, so the numerical solution is the answer you get from puting numbers in the analytical solution? :P

Ah, yes.
But then don't you need to integrate it again, so it would become something like

∫∫(1/y^2) dy = - ln |y| + Cy + C1 (Those constants don't look right) ?
No, the original DE was only first order $y' = y^2 + x$, so the simplified separable equation I considered was just $y' = y^2$ (first order). Unfortunately the second order equation $y'' = y^2$ wouldn't separate like that anyway.

Ah, so the numerical solution is the answer you get from puting numbers in the analytical solution? :P
Not really, that would probably just be called plotting the analytic solution. Take a look a the simplest type of DE solver like Eulers method ( http://en.wikipedia.org/wiki/Euler_method ) to get an understanding of what it really means to solve a DE numerically.

toneboy1
You are ofcourse right, I just looked. I could swear it was y′′=y^2 before.
So why could we not separate y′′=y^2, is there an easy way of doing that? (also do the constants from integration integrate like that from the double integral?)

Ah, I understand what Simon meant now.