473,721 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need help with ODE solver from scipy

Hi,

OK, I'm trying to figure out how to use the ODE solver
(scipy.integrat e.ode.ode). Here's what I'm doing (in iPython)

y0 = [0,1,1]
dt = 0.01
tEnd = 12
t0 = 0
Y = zeros([tEnd/dt, 3])

As an aside, I've used this assignment for Y in the past and it
worked. When I tried it this morning I got a TypeError and a message
saying I needed to use an integer. So, instead...

Y = zeros([int(tEnd/dt), 3])
T = zero([int(tEnd/dt)])
index = 0
def foo(t,y):
dy = zeros([3])
dy[0] = y[1]*y[2]
dy[1] = -y[0]*y[2]
dy[2] = -0.51*y[0]*y[1]
return dy

r = ode(foo).set_in tegrator('vode' ).set_initial_v alue(y0,t0)
while r.successful() and r.t < tEnd:
r.integrate(r.t +dt)
Y[index] = r.y
T[index] = r.t
index += 1

As a further aside, this system of three coupled linear ODE's is from
an example in MATLAB's documentation on their function ode45, so I
know what I 'should' get. The while loop and call to ode is adapted
from scipy's (very limited) documentation on scipy.integrate .ode.ode.

At the end of this while loop I've gotten a few different results
depending on what I have no idea. This morning another TypeError
exception was thrown, saying:

TypeError: Array can not be safely cast to required type.

Although, to be fair this is after the output from one iteration:

array([0.01, 1. , 1. ])

So, clearly this isn't working right. Does anyone have any experience
using this function or anything they can contribute?

thanks,
trevis

Apr 24 '07 #1
1 4901
T.Crane wrote:
Hi,

OK, I'm trying to figure out how to use the ODE solver
(scipy.integrat e.ode.ode).
You will get more help from the scipy-user list than you will here.

http://www.scipy.org/Mailing_Lists
Here's what I'm doing (in iPython)

y0 = [0,1,1]
dt = 0.01
tEnd = 12
t0 = 0
Y = zeros([tEnd/dt, 3])

As an aside, I've used this assignment for Y in the past and it
worked. When I tried it this morning I got a TypeError and a message
saying I needed to use an integer.
Well, the current behavior is correct. When you give us a float instead of an
int for a dimension, we shouldn't guess what you want. Particularly, in this
case, truncating is incorrect. I ran your code and eventually wound up with an
IndexError because your iteration ran past the end of Y and T.
So, instead...

Y = zeros([int(tEnd/dt), 3])
T = zero([int(tEnd/dt)])
Also, a better way to do this is simply to leave these as lists and simply
append to them. That way, you don't have to manage indices.
index = 0
def foo(t,y):
dy = zeros([3])
dy[0] = y[1]*y[2]
dy[1] = -y[0]*y[2]
dy[2] = -0.51*y[0]*y[1]
return dy

r = ode(foo).set_in tegrator('vode' ).set_initial_v alue(y0,t0)
while r.successful() and r.t < tEnd:
r.integrate(r.t +dt)
Y[index] = r.y
T[index] = r.t
index += 1

As a further aside, this system of three coupled linear ODE's is from
an example in MATLAB's documentation on their function ode45, so I
know what I 'should' get. The while loop and call to ode is adapted
from scipy's (very limited) documentation on scipy.integrate .ode.ode.

At the end of this while loop I've gotten a few different results
depending on what I have no idea. This morning another TypeError
exception was thrown, saying:

TypeError: Array can not be safely cast to required type.

Although, to be fair this is after the output from one iteration:

array([0.01, 1. , 1. ])

So, clearly this isn't working right. Does anyone have any experience
using this function or anything they can contribute?
I tried your example and it worked for me (after fixing the IndexError). Could
you come to scipy-user with the complete code that you ran (the one above isn't
the one you ran; there is at least one typo), and the full traceback of the error?

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco

Apr 24 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2638
by: hawkesed | last post by:
Hi All, has anyone out there recently set up scipy on Windows? Cause I am trying to do so know and I am not having much luck. I have ActiveState and Plone. When I try to import scipy in ActiveState it says >>> import scipy Traceback (most recent call last): File "<interactive input>", line 1, in ? ImportError: No module named scipy >>> from scipy import * Traceback (most recent call last):
0
1774
by: engsolnorm | last post by:
A co-worker and I want to increase our knowledge of Python. I have a tiny bit of exposure to python. He has none, but has wide experience with C, C++, NET, C#, etc. We agreed we'd do a Sudoku solver. I'd do the GUI, he would do the solver code. My question is this: I assume that once I invoke mauinloop, the loop just cycles between bound events...(if not true, please tell me)...so how do I "branch" out to the solver code, which will be in...
7
3053
by: nitro | last post by:
Hi, I am using a Debian system. I installed NumPy and everything works well. When I try to install SciPy, I get the following error. Any help would be appreciated. === idf@server1:~/scipy/scipy-0.4.4$ python setup.py install import core -> failed: /usr/lib/python2.3/site-packages/numpy/core/multiarray.so: undefined
1
8075
by: tkpmep | last post by:
I installed SciPy and NumPy (0.9.5, because 0.9.6 does not work with the current version of SciPy), and had some teething troubles. I looked around for help and observed that the tutorial is dated October 2004, and is not as thorough as Python's documentation. Is there an alternative source of information that lists all the functions and their usage? I tried using scipy.info to get information on the std function in the stats libary,...
0
1501
by: Julien Fiore | last post by:
Hi, I have problems trying to install the scipy.weave package. I run Python 2.4 on windows XP and my C compiler is MinGW. Below is the output of scipy.weave.test(). I read that the tests should last several minutes, but in my case it only lasts a few seconds. Thanks in advance for any help. Julien Fiore
2
9736
by: I. Myself | last post by:
And it has to run on Windows, so it can't use xplt. I would prefer that it use the simplest multi-dimensional model, z = k + a*x1 + b*x2 + c*x3 + d*x4 Anyone have such a thing? Thanks, Mitchell Timin
22
4714
by: James Stroud | last post by:
Hello All, This is annoying. I am trying to build scipy right now but every .so file requires my adding "-lpython2.5 -lpthread -lm -lutil -ldl -shared" to the ld flags. Main Question: When building with "setup.py", where can I include this information so I don't have to link every .so file by hand? Also, why would this not be caught by the developers of scipy and numpy?
2
3940
by: robert | last post by:
I'm using latest numpy & scipy. What is this problem ? : RuntimeError: module compiled against version 1000002 of C-API but this version of numpy is 1000009 Traceback (most recent call last): File "<interactive input>", line 1, in ? File "C:\PYTHON23\Lib\site-packages\scipy\stats\__init__.py", line 7, in ? from stats import * File "C:\PYTHON23\Lib\site-packages\scipy\stats\stats.py", line 191, in ? import scipy.special as special File...
7
14395
by: Holger Fitschen | last post by:
Hi to all, I want to use the Excel solver in a VB.Net project. The macro Sub Makro1Solver() Application.Run "Solver.xla!Auto_Open" SolverReset Worksheets(1).Select Worksheets(1).Range("B9").Select
0
8738
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9376
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9234
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9086
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8028
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6678
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5994
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2599
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.