0
$\begingroup$

I am trying to get a solution to a non-linear ODE, below is the code that works for my problem.

s = NDSolve[{y'''[x] + y[x]^2 y''[x] - y'[x] == 0, y[0] == 0, y'[0] == 0, y''[1] == 1}, y, {x, 0, 1}];
Plot[Evaluate[{y[x], y'[x], y''[x]} /. s], {x, 0, 1}]

1 Question how do you get the equations of the lines that are being plotted? So say on x from 0 to 1 what is the equation of the line.

2 How do solve the same problem but using a substitution of u=dy/dx?

u''[x] + y[x]^2 u'[x] - u[x] == 0, u[0] == 0, u'[1] == 1

and we need to integrate to get the y value, not sure how to set that as a BC as well.

Thank you

$\endgroup$
3
  • 1
    $\begingroup$ equation of the line is s , it is InterpolatingFunction. type s to see it. You do not need to solve the problem again. The derivative is already here. You can either take derivative of the solution, of change y by y,y' in the NDSOlve itself, and NDSolve will return y' as well as y $\endgroup$
    – Nasser
    Commented Dec 1, 2013 at 8:26
  • $\begingroup$ I see that the solution is in s, and when I type s it gives me this InterpolatingFunction. I looked at the documentation, I do not see how to get a numeric equation of the line. $\endgroup$
    – user10894
    Commented Dec 1, 2013 at 17:23
  • $\begingroup$ Right, I can get the value of y[x] from the first two lines of code. This is what I have, but does not seem to work, $NDSolve[{u''[x] + y[x]^2 u'[x] - u[x] == 0, u[0] == 0, u'[1] == 1}, {x}, {x, 0, 1}]$ $\endgroup$
    – user10894
    Commented Dec 1, 2013 at 17:27

1 Answer 1

1
$\begingroup$

You can't get an exact solution with Mathematica, but you may approximate it, for example with polynomials:

s = NDSolve[{y'''[x] + y[x]^2 y''[x] - y'[x] == 0, y[0] == 0, y'[0] == 0, y''[1]== 1}, y, {x, 0, 1}];
data = Table[{x, y[x] /. s[[1]]}, {x, 0, 1, .01}];
Manipulate[
 Column[{#, Show[ListPlot@data, Plot[#, {x, 0, 1}, PlotStyle -> {Thick, Red}], ImageSize -> 400]} &@ 
        Fit[data, Array[x^# &, n, 0], x]],
 {n, 1, 10, 1}]

Mathematica graphics

$\endgroup$
1
  • $\begingroup$ Thank you! An approximation is what I'm looking for. Just wasn't sure how to get the polynomial. $\endgroup$
    – user10894
    Commented Dec 1, 2013 at 23:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.