0

I have a bit of code I'm struggling with; modelling a cannonball, so far I have answered task one, with the code pasted below, but I can't get my head around task two, so if someone could help me with that, I'll be very grateful!

Task 1

def f(r, t):
    '''Implements differential equation for cannonball from state vector r and time t'''
    
    # Unpack array of the state
    x, y, vx, vy = r
    
    # these variables should updated in your code to be the derivatives of 
    # the x, y positions and the derivative of the x, y velocities. 
    dx_t, dy_dt, dvx_dt, dvy_dt = 0, 0, 0, 0
    
    # YOUR CODE HERE
    
    # Drag coefficient, projectile radius (m), area (m2) and mass (kg).
    
    kappa = 0.47
    r_cb = 0.15
    A = math.pi * r_cb ** 2
    rho_lead = 11343.
    m = mass_cb
    
    # Air density (kg.m-3), acceleration due to gravity (m.s-2).
    rho_air = 1.23
    g = 9.81
    # For convenience, define  this constant.
    k = 0.5 * kappa * rho_air * A

    # Initial speed and launch angle (from the horizontal).
    v0 = 200.00

    x, y, vx, vy = r
    
    dx_dt = vx
    dy_dt = vy
    
    speed = numpy.hypot(vx, vy)
        
    dvx_dt = -k/m * speed * vx
    dvy_dt = -k/m * speed * vy - g
        
    return numpy.array([dx_dt, dy_dt, dvx_dt, dvy_dt])

And then this is task 2, the one I'm struggling with:

Task 2

MarianD
  • 13,096
  • 12
  • 42
  • 54
  • 1
    Welcome to [Stack Overflow.](https://stackoverflow.com/ "Stack Overflow"). In order for us to help you, it is necessary that you show your effort and submit data to be used to reproduce your problem. While providing an image is helpful, it doesn't allow for reproducing the issue. Please edit your question to show a minimal reproducible set. See [Minimal Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example "Minimal Reproducible Example") for details. – itprorh66 Nov 06 '21 at 15:22
  • 1
    Sorry I don't understand what you mean? I've both shown my attempt and all necessary data is provided? – Sean Ambrose Nov 06 '21 at 16:47
  • 1
    DO NOT post images of code, data, error messages, etc. - copy or type the text into the question. Please reserve the use of images for diagrams or demonstrating rendering bugs, things that are impossible to describe accurately via text. For more information please see the Meta FAQ entry [Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question/285557#285557) – itprorh66 Nov 06 '21 at 17:24
  • Please add the questions as text, not as image. Please also add more information about what you tried for task 2 and where specifically you encountered which problem. Did you look up Euler's method for solving differential equations on Wikipedia and in your classes documentation? – JohanC Nov 06 '21 at 19:39
  • Apologies for that, I thought that the best way would be an image since its a less overwhelming amount of code. And yes, I am familiar with coding a numerical approach under Euler's method, my issue is more that I don't understand how to incorporate an inputted array into that method, and then code a loop to pass those values through a formula and then have it be stored in the array each time. – Sean Ambrose Nov 06 '21 at 21:35

0 Answers0