Ask Your Question
0

solve ode on given interval

asked 2017-06-10 14:24:58 +0100

soking gravatar image

updated 2017-06-13 11:19:21 +0100

Hi,

I would like to tell Sage to solve ode on a given interval that I will specify. My final goal is to use this method to solve ode that contains 'piecewise' function like 2*diff(u,x) + u == f(x), where

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

Thanks.

edit retag flag offensive close merge delete

Comments

did you try the approach suggested in your previous post, to write $f$ as a sum of unit_step functions? for instance, here it would be unit_step(t)*unit_step(1-t)*t + unit_step(t-1)*unit_step(2-t)*(-t+2). perhaps a method to_unit_step of piecewise functions could be useful to have..

mforets gravatar imagemforets ( 2017-06-11 18:13:59 +0100 )edit

No, I didn't think about the problem that way, I was rather think of a way to make Sage solve the ode on a specified interval. But, thanks, it's still something that works (at least for this problem).

soking gravatar imagesoking ( 2017-06-13 10:39:13 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-06-11 22:53:21 +0100

calc314 gravatar image

Here is a numerical solution using that suggested from your previous post.

var('u x')
f=x*(unit_step(x)-unit_step(x-1))+(2-x)*(unit_step(x-1))
ode = -1/2*(u)+f
ans=desolve_rk4(ode,u,ics=[-1,3],ivar=x,end_points=2,step=0.1)
solnplot=line(ans,color='red')
dirfield=streamline_plot(ode,(x,-1,2),(u,-1,4))
solnplot+dirfield
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: 2017-06-10 14:24:58 +0100

Seen: 380 times

Last updated: Jun 13 '17