Ask Your Question

Access integration constant

asked 2017-02-02 12:10:46 +0200

maaaaaaartin gravatar image


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?


edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2017-02-02 15:37:16 +0200

eric_g gravatar image

Like this (for instance setting the integration constant to 2):

sage: sol2 = sol.subs({SR.var('_C'): 2})
sage: print("sol = {}".format(sol2))
sol = 2
edit flag offensive delete link more

answered 2017-02-10 14:52:38 +0200

maaaaaaartin gravatar image

For the record, a workaround is to declare var('_C')right before solve(sol, _C).

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2017-02-02 12:10:46 +0200

Seen: 560 times

Last updated: Feb 10 '17