Ask Your Question
0

ode and piecewise function

asked 2017-06-08 16:38:47 +0100

soking gravatar image

Hi all,

I am trying to solve, using Sage, an ode which includes a piecewise. For that I wrote the following piece of code which raises an error :

f = piecewise([(RealSet.unbounded_below_open(0),0), (RealSet.unbounded_above_closed(0),10)])
u = function('u')(x)
eqn = 2*diff(u,x) + u == f(x)
u = desolve(eqn, u, ivar=x)
show(expand(u))

Since the error vanishses when I replace the function f by either of the functions exp or log, I guess the problem is coming from the piecewise function. Could anyone help me solve this issue and explain what is wrong here?

Thanks

edit retag flag offensive close merge delete

Comments

Hmm, I'm not sure whether our piecewise functions are supported with Maxima's ode solvers. Note that Maxima has its own piecewise implementation which may allow this directly within Maxima.

kcrisman gravatar imagekcrisman ( 2017-06-08 16:45:30 +0100 )edit

Does it mean that I have to switch to Maxima in order to solve such ode?

soking gravatar imagesoking ( 2017-06-08 16:48:43 +0100 )edit

I don't know; I'm just suggesting that could provide a solution. Of course, for numerical solutions there are good options. Also, I believe Sage does support Dirac and Heaviside functions now so they may work fine with this and desolve.

kcrisman gravatar imagekcrisman ( 2017-06-08 19:06:46 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2017-06-08 21:09:18 +0100

eric_g gravatar image

For you concrete example, you can use unit_step instead of piecewise:

sage: f(x) = 10*unit_step(x)
sage: u = function('u')(x)
sage: eqn = 2*diff(u,x) + u == f(x)
sage: u = desolve(eqn, u, ivar=x)
sage: u
(5*(e^(1/2*x) - 1)*sgn(x) + _C + 5*e^(1/2*x) - 5)*e^(-1/2*x)
edit flag offensive delete link more

Comments

Thank you, for your answer, but could I have a more general solution because I can't apply your answer when for instance

f = piecewise([((-1,0),0), ((0,1),x), ((1,2),2-x), (RealSet.unbounded_above_closed(2),0)])

I thought of telling sage to solve the ode on each interval, but I don't see how to do it with Sage.

soking gravatar imagesoking ( 2017-06-09 10:22:51 +0100 )edit

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: 2017-06-08 16:38:47 +0100

Seen: 610 times

Last updated: Jun 08 '17