ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 07 Nov 2012 04:27:25 +0100How to solve an implicit differential equation numerically?https://ask.sagemath.org/question/9506/how-to-solve-an-implicit-differential-equation-numerically/I tried Mathematica for this, but didn't see how to do it.
Is it possible to solve an equation of the following kind?
diff(R(t),t) == C1*(C2 - C3*1/R(t))*(1/R(t) + 1/sqrt(C4*t))
where t is a variable, R(t) is a function of t and C1 to C4 are constants
Any help would be appreciated.
Tue, 06 Nov 2012 11:47:43 +0100https://ask.sagemath.org/question/9506/how-to-solve-an-implicit-differential-equation-numerically/Answer by calc314 for <p>I tried Mathematica for this, but didn't see how to do it.
Is it possible to solve an equation of the following kind?</p>
<pre><code>diff(R(t),t) == C1*(C2 - C3*1/R(t))*(1/R(t) + 1/sqrt(C4*t))
</code></pre>
<p>where t is a variable, R(t) is a function of t and C1 to C4 are constants</p>
<p>Any help would be appreciated.</p>
https://ask.sagemath.org/question/9506/how-to-solve-an-implicit-differential-equation-numerically/?answer=14232#post-id-14232One way to approach this differential equation numerically is:
var('r,t')
c1=0.2
c2=10
c3=5
c4=4
g(r,t)=c1*(c2-c3/r)*(1/r+1/sqrt(c4*t))
f=[SR(1),g(r,t)]
soln1=desolve_odeint(f,[1,1],srange(0,10,0.05),[t,r])
p=line(soln1)
p+=plot_vector_field([1/sqrt(1+g(t,r)^2),g(t,r)/sqrt(1+g(t,r)^2)],(t,0,10),(r,0,10))
show(p)
From a local installation of Sage, you can also use `maxima` to launch a window that contains the direction field and allows you to click in the window to indicate your initial condition.
maxima('plotdf([1,.2*(10-5/r)*(1/r+1/sqrt(4*t))],[t,r],[t,0,10],[r,0,10])')
Finally, for an option outside of Sage that is very nice, I also recommend using `pplane` and `dfield` at: http://math.rice.edu/~dfield/dfpp.htmlTue, 06 Nov 2012 13:44:46 +0100https://ask.sagemath.org/question/9506/how-to-solve-an-implicit-differential-equation-numerically/?answer=14232#post-id-14232Comment by clenz for <p>One way to approach this differential equation numerically is:</p>
<pre><code>var('r,t')
c1=0.2
c2=10
c3=5
c4=4
g(r,t)=c1*(c2-c3/r)*(1/r+1/sqrt(c4*t))
f=[SR(1),g(r,t)]
soln1=desolve_odeint(f,[1,1],srange(0,10,0.05),[t,r])
p=line(soln1)
p+=plot_vector_field([1/sqrt(1+g(t,r)^2),g(t,r)/sqrt(1+g(t,r)^2)],(t,0,10),(r,0,10))
show(p)
</code></pre>
<p>From a local installation of Sage, you can also use <code>maxima</code> to launch a window that contains the direction field and allows you to click in the window to indicate your initial condition.</p>
<pre><code>maxima('plotdf([1,.2*(10-5/r)*(1/r+1/sqrt(4*t))],[t,r],[t,0,10],[r,0,10])')
</code></pre>
<p>Finally, for an option outside of Sage that is very nice, I also recommend using <code>pplane</code> and <code>dfield</code>at: <a href="http://math.rice.edu/~dfield/dfpp.html">http://math.rice.edu/~dfield/dfpp.html</a></p>
https://ask.sagemath.org/question/9506/how-to-solve-an-implicit-differential-equation-numerically/?comment=18745#post-id-18745Great, that works! Thank you for the competent answer!Wed, 07 Nov 2012 04:27:25 +0100https://ask.sagemath.org/question/9506/how-to-solve-an-implicit-differential-equation-numerically/?comment=18745#post-id-18745