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.Fri, 10 Feb 2017 14:52:38 +0100Access integration constanthttps://ask.sagemath.org/question/36439/access-integration-constant/Hi,
Consider the following code:
> x = var('x')
> f = function('f')(x)
> sol = desolve(diff(f,x), [f,x])
> print "sol =", sol
> solve(sol, _C)
For which I'm getting `NameError: name '_C' is not defined`. What would be the right way to set the integration constant after the resolution of the differential equation?
Thanks!Thu, 02 Feb 2017 12:10:46 +0100https://ask.sagemath.org/question/36439/access-integration-constant/Answer by eric_g for <p>Hi,</p>
<p>Consider the following code:</p>
<blockquote>
<p>x = var('x')</p>
<p>f = function('f')(x)</p>
<p>sol = desolve(diff(f,x), [f,x])</p>
<p>print "sol =", sol</p>
<p>solve(sol, _C)</p>
</blockquote>
<p>For which I'm getting <code>NameError: name '_C' is not defined</code>. What would be the right way to set the integration constant after the resolution of the differential equation?</p>
<p>Thanks!</p>
https://ask.sagemath.org/question/36439/access-integration-constant/?answer=36442#post-id-36442Like this (for instance setting the integration constant to `2`):
sage: sol2 = sol.subs({SR.var('_C'): 2})
sage: print("sol = {}".format(sol2))
sol = 2
Thu, 02 Feb 2017 15:37:16 +0100https://ask.sagemath.org/question/36439/access-integration-constant/?answer=36442#post-id-36442Answer by maaaaaaartin for <p>Hi,</p>
<p>Consider the following code:</p>
<blockquote>
<p>x = var('x')</p>
<p>f = function('f')(x)</p>
<p>sol = desolve(diff(f,x), [f,x])</p>
<p>print "sol =", sol</p>
<p>solve(sol, _C)</p>
</blockquote>
<p>For which I'm getting <code>NameError: name '_C' is not defined</code>. What would be the right way to set the integration constant after the resolution of the differential equation?</p>
<p>Thanks!</p>
https://ask.sagemath.org/question/36439/access-integration-constant/?answer=36537#post-id-36537For the record, a workaround is to declare `var('_C')`right before `solve(sol, _C)`.Fri, 10 Feb 2017 14:52:38 +0100https://ask.sagemath.org/question/36439/access-integration-constant/?answer=36537#post-id-36537