Ask Your Question

Defining constants after solving ODE/PDE

asked 2015-01-01 21:26:59 +0200

Marios Papachristou gravatar image


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 flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-01-02 07:41:16 +0200

rws gravatar image

updated 2015-01-02 16:16:39 +0200

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
sage: f.subs(c=10)
sage: f.subs(c=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)
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

1 follower


Asked: 2015-01-01 21:26:59 +0200

Seen: 494 times

Last updated: Jan 02 '15