[SciPy-User] _dop.error: failed in processing argument list for call-back fcn.
SHIHUI GUO
sguo@bournemouth.ac...
Fri Mar 1 06:11:55 CST 2013
Thanks Warren.
You are so helpful!
Shihui
On 1 March 2013 04:57, Warren Weckesser <warren.weckesser@gmail.com> wrote:
> On 2/26/13, SHIHUI GUO <sguo@bournemouth.ac.uk> wrote:
> > Hi Warren,
> >
> > Thanks for this. The major issue is that I declared the "param" in
> function
> > definition, but didn't pass that when calling.
> >
> > Another question, when we do:
> > ==========================
> > while test.successful() and test.t<t1:
> > test.integrate(test.t+dt)
> > ==========================
> > the result is returned after each time step. Is there any default way I
> > could specify the time span and get the result over the whole time span,
> > instead of individual integrative step?
> >
>
> Yes, in fact, that is what it is doing, but the loop is set up to get
> a value every `dt` time units. If you want just the final value,
> eliminate the loop, and just give the final time as the argument to
> test.integrate.
>
> For example, the following computes the solution to dy/dt = -y with
> y(0) = 1 at time t=10:
>
> -----
> In [34]: def func(t, y):
> ....: return -y
> ....:
>
> In [35]: solver = ode(f=func)
>
> In [36]: solver.set_integrator("lsoda")
> Out[36]: <scipy.integrate._ode.ode at 0x2b59350>
>
> In [37]: solver.set_initial_value(1.0)
> Out[37]: <scipy.integrate._ode.ode at 0x2b59350>
>
> In [38]: result = solver.integrate(10.0) # Get the solution at t=10.
>
> In [39]: result
> Out[39]: array([ 4.53998024e-05])
>
> In [40]: np.exp(-10)
> Out[40]: 4.5399929762484854e-05
>
> In [41]: solver.successful()
> Out[41]: True
> -----
>
> Warren
>
>
> > Thanks.
> >
> > Shihui
> >
> >
> > On 26 February 2013 11:16, Warren Weckesser
> > <warren.weckesser@gmail.com>wrote:
> >
> >> On 2/26/13, SHIHUI GUO <sguo@bournemouth.ac.uk> wrote:
> >> > HI all,
> >> >
> >> > I want to use scipy to implement an oscillator, ie. solving a
> >> > secod-order
> >> > ordinary differential equation, my code is:
> >> > ===================================
> >> > from scipy.integrate import ode
> >> >
> >> > y0,t0 = [0, 1], 0
> >> >
> >> > def fun(t, y, params):
> >> > rou = 1
> >> > omega = 10
> >> > sigma = 1
> >> > # convergence rate, ie, lambda
> >> > conrate = 10
> >> > temp = -conrate*((y[0]^2+y[1]^2)/rou^2-sigma)
> >> > dy = temp*y[0] - omega*y[1]
> >> > ddy = omega*y[0] + temp*y[1]
> >> > return [dy, ddy]
> >> >
> >> > test = ode(fun).set_integrator('dopri5')
> >> > test.set_initial_value(y0, t0)
> >> > t1 = 10
> >> > dt = 0.1
> >> >
> >> > while test.successful() and test.t<t1:
> >> > test.integrate(test.t+dt)
> >> > print test.t, test.yy
> >> > ===================================
> >> >
> >> > ===================================
> >> > The error says:
> >> > _dop.error: failed in processing argument list for call-back fcn.
> >> > File "/home/shepherd/python/research/testode.py", line 23, in <module>
> >> > test.integrate(test.t+dt)
> >> > File
> >> >
> >>
> "/home/shepherd/epd/epd_free-7.3-2-rh5-x86/lib/python2.7/site-packages/scipy/integrate/_ode.py",
> >> > line 333, in integrate
> >> > self.f_params, self.jac_params)
> >> > File
> >> >
> >>
> "/home/shepherd/epd/epd_free-7.3-2-rh5-x86/lib/python2.7/site-packages/scipy/integrate/_ode.py",
> >> > line 827, in run
> >> > tuple(self.call_args) + (f_params,)))
> >> > ===================================
> >> >
> >> > Previously I use the ubuntu default python, and scipy is 0.9.0. Some
> >> thread
> >> > says it is a bug and has been fixed in 0.10.0, so I switched to
> >> enthought,
> >> > now the scipy is newest version, but the error remains.
> >> >
> >> > Thanks for any help.
> >> >
> >> > Shihui
> >> >
> >>
> >>
> >> There are a few problems in your code.
> >>
> >> You haven't told the `ode` object that your function accepts the extra
> >> argument `params`. Normally you would do this with
> >> `test.set_f_params(...)`, but since your function doesn't actually use
> >> `params`, it is simpler to just change the function signature to
> >>
> >> def fun(t, y):
> >>
> >> Next, in Python, the operator to raise a value to a power is **, not
> >> ^, so the formula for `temp` should be:
> >>
> >> temp = -conrate*((y[0]**2+y[1]**2)/rou**2-sigma)
> >>
> >> Finally, the attribute for the solution is `y`, not `yy`, so the last
> >> line should be:
> >>
> >> print test.t, test.y
> >>
> >>
> >> Cheers,
> >>
> >> Warren
> >>
> >>
> >> > --
> >> > *
> >> >
> >>
> ---------------------------------------------------------------------------------------
> >> > *
> >> >
> >> > SHIHUI GUO
> >> > National Center for Computer Animation
> >> > Bournemouth University
> >> > United Kingdom
> >> >
> >> > BU is a Disability Two Ticks Employer and has signed up to the Mindful
> >> > Employer charter. Information about the accessibility of University
> >> > buildings can be found on the BU DisabledGo webpages [
> >> > http://www.disabledgo.com/en/org/bournemouth-university ]
> >> > This email is intended only for the person to whom it is addressed and
> >> may
> >> > contain confidential information. If you have received this email in
> >> error,
> >> > please notify the sender and delete this email, which must not be
> >> > copied,
> >> > distributed or disclosed to any other person.
> >> > Any views or opinions presented are solely those of the author and do
> >> > not
> >> > necessarily represent those of Bournemouth University or its
> subsidiary
> >> > companies. Nor can any contract be formed on behalf of the University
> >> > or
> >> its
> >> > subsidiary companies via email.
> >> >
> >> >
> >> >
> >> _______________________________________________
> >> SciPy-User mailing list
> >> SciPy-User@scipy.org
> >> http://mail.scipy.org/mailman/listinfo/scipy-user
> >>
> >>
> >>
> >
> >
> > --
> > *
> >
> ---------------------------------------------------------------------------------------
> > *
> >
> > SHIHUI GUO
> > National Center for Computer Animation
> > Bournemouth University
> > United Kingdom
> >
> > BU is a Disability Two Ticks Employer and has signed up to the Mindful
> > Employer charter. Information about the accessibility of University
> > buildings can be found on the BU DisabledGo webpages [
> > http://www.disabledgo.com/en/org/bournemouth-university ]
> > This email is intended only for the person to whom it is addressed and
> may
> > contain confidential information. If you have received this email in
> error,
> > please notify the sender and delete this email, which must not be copied,
> > distributed or disclosed to any other person.
> > Any views or opinions presented are solely those of the author and do not
> > necessarily represent those of Bournemouth University or its subsidiary
> > companies. Nor can any contract be formed on behalf of the University or
> its
> > subsidiary companies via email.
> >
> >
> >
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
>
--
*
---------------------------------------------------------------------------------------
*
SHIHUI GUO
National Center for Computer Animation
Bournemouth University
United Kingdom
BU is a Disability Two Ticks Employer and has signed up to the Mindful Employer charter. Information about the accessibility of University buildings can be found on the BU DisabledGo webpages [ http://www.disabledgo.com/en/org/bournemouth-university ]
This email is intended only for the person to whom it is addressed and may contain confidential information. If you have received this email in error, please notify the sender and delete this email, which must not be copied, distributed or disclosed to any other person.
Any views or opinions presented are solely those of the author and do not necessarily represent those of Bournemouth University or its subsidiary companies. Nor can any contract be formed on behalf of the University or its subsidiary companies via email.
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20130301/07e25031/attachment.html
More information about the SciPy-User
mailing list