# Defining constants after solving ODE/PDE

Hello

Solving the differential equation $f'(x) = f(x)$ the answer leads to $f(x) = ce^x$ where $c$ is a constant. How can I generically solve this ODE in SAGE and define $c$ afterwards (I don't want to use ics)?

Consider this script

x = var('x')
f = function('f',x)
f = desolve(diff(f,x) == f(x), f, ival=x)
print str(f(x))
>> ce^x
#I want to define c afterwards


A method I found:

#continue the previous prompt
f(x,c) = f(x)
h(x) = f(x,10)


Is there something else that I can do?

edit retag close merge delete

Sort by » oldest newest most voted

First, although you set f to be a function, you later overwrite it with the result of desolve which is a symbolic expression. You can, instead of using it as function, simply substitute any other expression for c:

f = desolve(diff(f,x) == f(x), f, ival=x)
sage: f
c*e^x
sage: f.subs(c=10)
10*e^x
sage: f.subs(c=sin(x))
e^x*sin(x)


If you want that in function notation, assign the expression to a function call:

sage: f(x,c)=f
sage: f
(x, c) |--> c*e^x
sage: f(x,10)
10*e^x

more