Ask Your Question
1

Defining constants after solving ODE/PDE

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

Marios Papachristou gravatar image

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

1 Answer

Sort by ยป oldest newest most voted
2

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

rws gravatar image

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

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
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

Stats

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

Seen: 615 times

Last updated: Jan 02 '15