Ask Your Question

Python function in ODE not producing needed results

asked 2015-10-29 16:22:05 +0100

calc314 gravatar image

I am using the dirac_delta function in an ODE, and since it is treated like a Python function, it is not evaluated as I would like in the ODE solver. I think this is a matter of having a Python function when I need a symbolic function, but I cannot figure out how to get around it. My code is below. Any ideas?

var('A p y t s v')
alpha = 1
beta = -1/sqrt(3)
omega = 1
F(t) = [SR(1),v,-omega^2*y+A*dirac_delta(t-p)]
ty=[[a[0],a[1]] for a in ans]
tv=[[a[0],a[2]] for a in ans]
edit retag flag offensive close merge delete


I think you are right. It's possible that Maxima would have an implementation of Dirac delta that you could use directly within Maxima, though.

kcrisman gravatar imagekcrisman ( 2015-10-29 20:31:20 +0100 )edit

Is there a way to use the ode solver with a python function in the vector field? I think I've done this before but what I tried in the past does not seem to work.

calc314 gravatar imagecalc314 ( 2015-10-29 21:28:53 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-10-30 02:45:33 +0100

calc314 gravatar image

In the end, I used ode_solver and an approximation of the delta function to get things working. Here is the code:

def lab(A=input_box(2,label='A',width=15),p=input_box(2,label='p',width=15),alpha = input_box(1,label='alpha',width=15),beta = input_box(1/sqrt(3),label='beta',width=15),omega = input_box(1,label='omega',width=15),interval=input_box((0,6),label='interval',width=20) ):
    def f(q):
        if q>p-w/2 and q<p+w/2:
            return 0

    def dy(t,y):
        return [ 1, y[2], -omega^2*y[1]+A*f(y[0]) ]

    ans=[a[1] for a in ans]
    ty=[[a[0],a[1]] for a in ans]
    tv=[[a[0],a[2]] for a in ans]
    p=line(ty,legend_label='y (position)')+line(tv,color='red',legend_label='v (velocity)')
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-10-29 16:22:05 +0100

Seen: 173 times

Last updated: Oct 30 '15