Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7614533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:25:39+00:00 2026-05-31T02:25:39+00:00

I would like to implement my own basic Runge-Kutta 4 integrator in Python. The

  • 0

I would like to implement my own basic Runge-Kutta 4 integrator in Python. The format should be something like this:

---- EXAMPLE set of equations ----
f1 = lambda x: x**2
f2 = lambda y: y**2
.
.
.
fn = lambda n: n**2
f = [f1, f2, f3, ... , fn]

result = integrate(f, other arguments [e.g. stepsize etc.])

---- result should be of format ----
result = [result1 result2 result3 ... resultn]

So basically I want to be able to define, for example, a set of three equations of motion, and be able to pass these to a function and access them to manipulate these equations inside of that function. How is that possible?

Ideally, I want to achive something similar to Matlabs ode45 function, which can be called for example as follows:

% ---- file 1 ---- %
function xp=F(t,x)
xp=zeros(2,1);
xp(1)=x(2);
xp(2)=-t*x(1)+exp(t)*x(2)+3*sin(2*t); 

% ---- file 2 ---- %
[t,x]=ode45(’file 1’,[t0,tf],[x10,x20]);

% where t0 tf initial and final values of t
% x10 x20 initial values of x

Note 1:
I have already looked at the source for dopri5 in SciPy but it is implemented in C and far too advanced for my purposes.

Note 2:
Let me know if what I’ve written above is not clear at all, which

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:25:40+00:00Added an answer on May 31, 2026 at 2:25 am

    DISCLAIMER: Python isn’t designed for writing this sort of low-level numeric stuff. It’s certainly good at managing it — numpy is a module specifically for handling large numeric datasets and doing calculations like this on them — but the actual number-crunching is done in low-level C or Fortran for speed. Writing your own integrator is an interesting learning exercise, but it won’t teach you that much about how Python is used normally. That said:


    You can do exactly what you asked for.

    >>> def integrate(fs):
    ...     print fs[0](1)
    ... 
    >>> f1 = lambda x: x**2
    >>> f2 = lambda x: x**3
    >>> 
    >>> fs = (f1, f2)
    >>> 
    >>> integrate(fs)
    1
    

    This makes sense, because functions are first-class objects in Python.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i would like to implement 'drawing modes' (in my own graphics library). That is
I would like to implement something similar to a c# delegate method in PHP.
I would like to implement a command line interface for a Java application. This
I would like to implement something similar to 37Signals's Yellow Fade effect. I am
I would like to implement my own button to reset the zoom. When calling
I would like to implement a data access object pattern in C++, but preferably
I would like to implement an interactive evolutionary algorithm for generating music (probably just
I would like to implement a producer/consumer scenario that obeys interfaces that are roughly:
I would like to implement a post build event that performs the following actions
I would like to implement the method User.calculate_hashed_password . I'm trying to use the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.