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.Thu, 07 Sep 2017 13:42:11 +0200Infinite initial conditions in ODE and arbitrary constanthttps://ask.sagemath.org/question/36493/infinite-initial-conditions-in-ode-and-arbitrary-constant/Is it possible to include infinite initial conditions in an ODE? For example,
ode_soln = desolve(ode, q, ics[0, -Infity])
throws and error.
Alternatively, I can leave the initial condition blank:
ode_soln = desolve(ode, q)
soln = solve(ode_soln, q)
show(soln[0])
Then output Includes an arbitrary constant written C
$$
q\left(t\right) = -\frac{p}{C {\left(p + 1\right)} + {\left(p + 1\right)} t}
$$
I tried to set a value for $C$ via,
show(soln[0].substitute(C = 0))
but it made no difference. Here $p$ I declared as a variable, and I can do things like
show(soln[0].substitute(p = 1))
to produce the expected output
$$
q\left(t\right) = -\frac{1}{2 {\left(C + t\right)}}
$$
So it seems that I need to refer to the arbitrary constant by some other name than $C$. How can I do this?Thu, 09 Feb 2017 02:37:45 +0100https://ask.sagemath.org/question/36493/infinite-initial-conditions-in-ode-and-arbitrary-constant/Answer by eric_g for <p>Is it possible to include infinite initial conditions in an ODE? For example,</p>
<pre><code>ode_soln = desolve(ode, q, ics[0, -Infity])
</code></pre>
<p>throws and error.</p>
<p>Alternatively, I can leave the initial condition blank:</p>
<pre><code>ode_soln = desolve(ode, q)
soln = solve(ode_soln, q)
show(soln[0])
</code></pre>
<p>Then output Includes an arbitrary constant written C
$$
q\left(t\right) = -\frac{p}{C {\left(p + 1\right)} + {\left(p + 1\right)} t}
$$</p>
<p>I tried to set a value for $C$ via,</p>
<pre><code>show(soln[0].substitute(C = 0))
</code></pre>
<p>but it made no difference. Here $p$ I declared as a variable, and I can do things like</p>
<pre><code>show(soln[0].substitute(p = 1))
</code></pre>
<p>to produce the expected output</p>
<p>$$
q\left(t\right) = -\frac{1}{2 {\left(C + t\right)}}
$$</p>
<p>So it seems that I need to refer to the arbitrary constant by some other name than $C$. How can I do this?</p>
https://ask.sagemath.org/question/36493/infinite-initial-conditions-in-ode-and-arbitrary-constant/?answer=36499#post-id-36499The answer to your second question (substituting for $C$) is
soln[0].substitute({SR.var('_C'): 0})
This is because constants that appear in solutions of ODEs, like `_C` (which is displayed as $C$), are not put in the global namespace, hence they have to be recovered from their names in the Symbolic Ring (SR) by `SR.var('_C')`.
Thu, 09 Feb 2017 12:43:50 +0100https://ask.sagemath.org/question/36493/infinite-initial-conditions-in-ode-and-arbitrary-constant/?answer=36499#post-id-36499Comment by Paul Bryan for <p>The answer to your second question (substituting for $C$) is</p>
<pre><code>soln[0].substitute({SR.var('_C'): 0})
</code></pre>
<p>This is because constants that appear in solutions of ODEs, like <code>_C</code> (which is displayed as $C$), are not put in the global namespace, hence they have to be recovered from their names in the Symbolic Ring (SR) by <code>SR.var('_C')</code>.</p>
https://ask.sagemath.org/question/36493/infinite-initial-conditions-in-ode-and-arbitrary-constant/?comment=38748#post-id-38748Excellent. That does the job, thank you.Thu, 07 Sep 2017 13:42:11 +0200https://ask.sagemath.org/question/36493/infinite-initial-conditions-in-ode-and-arbitrary-constant/?comment=38748#post-id-38748