1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. Aug 31, 2012 #1
    1. The problem statement, all variables and given/known data
    I want to find the general solution for y(x) if dy/dx = x + y^2 with initial cond't y(1) = 2

    2. Relevant equations

    3. 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!
  2. jcsd
  3. Aug 31, 2012 #2

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper

  4. Sep 1, 2012 #3
    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)

    *Please see attachment, .Gif link didn't show up properly*

    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!


    Attached Files:

    • img4.gif
      File size:
      11.6 KB
    Last edited: Sep 1, 2012
  5. Sep 1, 2012 #4

    Simon Bridge

    User Avatar
    Science Advisor
    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
  6. Sep 1, 2012 #5
    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?

  7. Sep 1, 2012 #6

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper

    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.
    you don't equate it to anything, you substitute it into: y'=x+y2
    The quotient rule is:
    (f/g)'=(gf'-fg')/g2 put f=z' and g=z.

    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?
  8. Sep 1, 2012 #7
    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!
  9. Sep 1, 2012 #8

    Simon Bridge

    User Avatar
    Science Advisor
    Homework Helper

    ... same reason I don't do g=-z: avoids misplacing the "-" sign later.
    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.)

    ... well, if the first line then the second ... however, what makes you think that [itex]Ce^{-x^2/2}[/itex] is a solution to [itex]z^\prime +xz = 0[/itex].

    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: Sep 1, 2012
  10. Sep 1, 2012 #9
    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
  11. Sep 1, 2012 #10


    User Avatar
    Science Advisor

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

    No, that's an "integrating factor" solution for the first order DE: [itex]z^{\prime} +xz = 0[/itex], not the 2nd order DE we're considering here.
  12. Sep 1, 2012 #11

    Simon Bridge

    User Avatar
    Science Advisor
    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
    [tex]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[/tex]... or, in Liebnitz notation:[tex]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[/tex]

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

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

    The actual solution is [itex]z(x)=c_1\text{Ai}(kx)+c_2\text{Bi}(kx): k^3=-1[/itex] 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?
  13. Sep 1, 2012 #12
    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)

  14. Sep 1, 2012 #13

    Simon Bridge

    User Avatar
    Science Advisor
    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
  15. Sep 1, 2012 #14
    I appreciate your guidance.
    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!
  16. Sep 1, 2012 #15


    User Avatar
    Science Advisor

    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 (Text):

    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);
    - 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 [itex]y' = y^2[/itex], with y(1)=2. It is trivial to solve (by separation) and obtain:
    [tex]y = \frac{1}{1.5-x}[/tex]

    It's interesting that although we changed the equation to completely omit the "[itex]+x[/itex]" 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).

    Attached Files:

    • de1.jpg
      File size:
      11.9 KB
    • de2.jpg
      File size:
      10.1 KB
    Last edited: Sep 1, 2012
  17. Sep 1, 2012 #16
    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.


    THey just came through
  18. Sep 1, 2012 #17


    User Avatar
    Science Advisor

    Analytically in this context literally mean "by analysis", rather than just plain dumb number crunching.

    @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.

    Not surprising, as this was also a 4th order runge kutta. :smile:

    No, [itex] \int (1/y^2) dy [/itex] is just [itex](-y^{-1} + C)[/itex], it's not log().
    Last edited: Sep 1, 2012
  19. Sep 1, 2012 #18

    Simon Bridge

    User Avatar
    Science Advisor
    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.
  20. Sep 1, 2012 #19
    Fancy that. That matlab info will be sure to come in useful.

    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
  21. Sep 2, 2012 #20


    User Avatar
    Science Advisor

    No, the original DE was only first order [itex]y' = y^2 + x[/itex], so the simplified separable equation I considered was just [itex]y' = y^2[/itex] (first order). Unfortunately the second order equation [itex]y'' = y^2[/itex] wouldn't separate like that anyway.

    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.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook