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 7508787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:44:21+00:00 2026-05-29T22:44:21+00:00

Hi I am working on a script that will solve and plot an ODE

  • 0

Hi I am working on a script that will solve and plot an ODE using the Runge Kutta method. I want to have the script use different functions so I can expand upon it later. If I write it with out the function definition it works fine, but with the def() it will not open a plot window or print the results. Than you!

from numpy import *
import matplotlib.pyplot as plt

#H=p^2/2-cosq
#p=dp=-dH/dq
#q=dq=dH/dp

t = 0
h = 0.5
pfa = []                        #Create arrays that will hold pf,qf values
qfa = []

while t < 10:
    q = 1*t
    p = -sin(q*t)

    p1 = p
    q1 = q
    p2 = p + h/2*q1
    q2 = q + h/2*p1
    p3 = p+ h/2*q2
    q3 = q+ h/2*p2
    p4 = p+ h/2*q3
    q4 = q+ h/2*p4
    pf = (p +(h/6.0)*(p1+2*p2+3*p3+p4))
    qf = (q +(h/6.0)*(q1+2*q2+3*q3+q4))

    pfa.append(pf)                   #append arrays
    qfa.append(qf)
    t += h                           #increase time step                        

print("test")
plt.plot(pfa,qfa)
print("test1")
plt.show()
print("tes2t")
  • 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-29T22:44:21+00:00Added an answer on May 29, 2026 at 10:44 pm

    If you have a function declared, you’ll need to call it at some point, e.g.:

    def rk(p,q,h):
        pass # your code here
    
    if __name__ == '__main__':
        rk(1,2,1)
    

    Putting the function call within the if __name__ == '__main__' block will ensure that the function is called only when you run the script directly, not when you import it from another script. ( More on that here in case you’re interested: What does if __name__ == "__main__": do? )

    And here’s an even better option; to avoid hard-coding fn args (your real code should have some error-handling for unexpected command-line input):

    def rk(p,q,h):
        pass # your code here
    
    if __name__ == '__main__':
        import argparse
        the_parser = argparse.ArgumentParser()
        the_parser.add_argument('integers', type=int, nargs=3)
        args = the_parser.parse_args()
        p,q,h = args.integers
        rk(p,q,h)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script that generates images from text using PHP. It's working fine
I am working on a script that will process user uploads to the server,
I'm currently working on a jQuery script that will translate the site's text into
I am working on a small bit of script that will allow for easy
I'm working to create a simple Python script that will ultimately tell you how
I'm working on a batch script that will let me delete files older then
I am working on a script that will handle email attachments. I see that,
I'm working on a script that will run as a scheduled task under a
I'm working on a script that needs to set up a Xerox Phaser printer
I'm working on a python script that starts several processes and database connections. Every

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.