ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 30 Dec 2017 21:13:14 -0600solving nonlinear second order ordinary differential equations numericallyhttp://ask.sagemath.org/question/40350/solving-nonlinear-second-order-ordinary-differential-equations-numerically/Are there any Sage tools that will numerically solve equations of, for example, this form:
y''(t)+f(t)(y'(t))^2+g(t)=0
(where the derivatives are with respect to t)?
Thanks,
WayneFri, 29 Dec 2017 10:08:41 -0600http://ask.sagemath.org/question/40350/solving-nonlinear-second-order-ordinary-differential-equations-numerically/Answer by eric_g for <p>Are there any Sage tools that will numerically solve equations of, for example, this form:</p>
<p>y''(t)+f(t)(y'(t))^2+g(t)=0</p>
<p>(where the derivatives are with respect to t)? </p>
<p>Thanks,
Wayne</p>
http://ask.sagemath.org/question/40350/solving-nonlinear-second-order-ordinary-differential-equations-numerically/?answer=40362#post-id-40362Yes there are such tools, but you have first to write your second order differential equation as a system of two first order equations, by introducing $z(t) = y'(t)$: $$y'(t)=z(t), \qquad z'(t) = -f(t) z(t)^2 - g(t)$$
Then you can use `desolve_system_rk4`. Type `desolve_system_rk4?` for details. An example of use is in cell 44 and below of [this notebook](http://nbviewer.jupyter.org/github/sagemanifolds/SageManifolds/blob/master/Worksheets/v1.1/SM_TOV.ipynb). Fri, 29 Dec 2017 15:05:49 -0600http://ask.sagemath.org/question/40350/solving-nonlinear-second-order-ordinary-differential-equations-numerically/?answer=40362#post-id-40362Comment by Wayne for <p>Yes there are such tools, but you have first to write your second order differential equation as a system of two first order equations, by introducing $z(t) = y'(t)$: $$y'(t)=z(t), \qquad z'(t) = -f(t) z(t)^2 - g(t)$$
Then you can use <code>desolve_system_rk4</code>. Type <code>desolve_system_rk4?</code> for details. An example of use is in cell 44 and below of <a href="http://nbviewer.jupyter.org/github/sagemanifolds/SageManifolds/blob/master/Worksheets/v1.1/SM_TOV.ipynb">this notebook</a>. </p>
http://ask.sagemath.org/question/40350/solving-nonlinear-second-order-ordinary-differential-equations-numerically/?comment=40390#post-id-40390Thanks very much Calc314! Clearly I have a lot to learn. I will work on this.Sat, 30 Dec 2017 21:13:14 -0600http://ask.sagemath.org/question/40350/solving-nonlinear-second-order-ordinary-differential-equations-numerically/?comment=40390#post-id-40390Comment by Wayne for <p>Yes there are such tools, but you have first to write your second order differential equation as a system of two first order equations, by introducing $z(t) = y'(t)$: $$y'(t)=z(t), \qquad z'(t) = -f(t) z(t)^2 - g(t)$$
Then you can use <code>desolve_system_rk4</code>. Type <code>desolve_system_rk4?</code> for details. An example of use is in cell 44 and below of <a href="http://nbviewer.jupyter.org/github/sagemanifolds/SageManifolds/blob/master/Worksheets/v1.1/SM_TOV.ipynb">this notebook</a>. </p>
http://ask.sagemath.org/question/40350/solving-nonlinear-second-order-ordinary-differential-equations-numerically/?comment=40365#post-id-40365Thanks Eric,
I meant the g(t) term to be a y(t) term so the equation looks like
y''(t)+f(t)(y'(t))^2 +y(t)=0
I don't think this is easily turned into a first order equation.
WayneFri, 29 Dec 2017 18:10:40 -0600http://ask.sagemath.org/question/40350/solving-nonlinear-second-order-ordinary-differential-equations-numerically/?comment=40365#post-id-40365Comment by calc314 for <p>Yes there are such tools, but you have first to write your second order differential equation as a system of two first order equations, by introducing $z(t) = y'(t)$: $$y'(t)=z(t), \qquad z'(t) = -f(t) z(t)^2 - g(t)$$
Then you can use <code>desolve_system_rk4</code>. Type <code>desolve_system_rk4?</code> for details. An example of use is in cell 44 and below of <a href="http://nbviewer.jupyter.org/github/sagemanifolds/SageManifolds/blob/master/Worksheets/v1.1/SM_TOV.ipynb">this notebook</a>. </p>
http://ask.sagemath.org/question/40350/solving-nonlinear-second-order-ordinary-differential-equations-numerically/?comment=40370#post-id-40370@eric_g's solution can handle this. Just replace $g(t)$ with $y(t)$. Here is an example with $f(t)=-2+\frac{t}{1+t}$.
var('t y z')
P=desolve_system_rk4([z,-z^2*(-2+t/(1+t))-y],[y,z],ics=[0.1,10,2],ivar=t,end_points=100)
Q=[ [t1,y1] for t1,y1,z1 in P]
line(Q).show()Sat, 30 Dec 2017 06:49:28 -0600http://ask.sagemath.org/question/40350/solving-nonlinear-second-order-ordinary-differential-equations-numerically/?comment=40370#post-id-40370