using an array in python
Question: I am currently trying to figure out how to store two sets of values, t and y,
in my program so that I can plot these data points on a graph. I believe the
correct method is to use an array, but I am not sure how to proceed.

    
    
    import numpy as np
    import matplotlib.pyplot as plt
    
    
    t = 0.0
    y = 0.0
    u = 0.0
    F = 0.2
    Wd = 2*3.14
    w0 = 1.5*Wd
    b = w0/4
    
    
    h= 0.05
    
    while (t <= 5.95):
        m1 = u
        k1 = (-w0**2)*np.sin(y) + u*(1-2*b) + F*(w0**2)*np.cos(Wd*t)
        m2 = u + (h / 2.) * k1
        t_2 = t + (h / 2.)
        y_2 = y +(h / 2.) * m1
        u_2 = m2
        k2 = (-w0**2)*np.sin(y_2) + u_2*(1-2*b) + F*(w0**2)*np.cos(Wd*t_2)
        m3 = u + (h / 2.) * k2
        t_3 = t + (h / 2.)
        y_3 = y + (h / 2.) * m2
        u_3 = m3
        k3 = (-w0**2)*np.sin(y_3) + u_3*(1-2*b) + F*(w0**2)*np.cos(Wd*t_3)
        m4 = u + h * k3
        t_4 = t + h
        y_4 = y + h * m3
        u_4 = m4
        k4 =  (-w0**2)*np.sin(y_4) + u_4*(1-2*b) + F*(w0**2)*np.cos(Wd*t_4)
        t = t + h
        y = y + (h / 6.) * (m1 + (2 * m2) + (2 * m3) + m4)
        u = u + (h / 6.) * (k1 + (2 * k2) + (2 * k3) + k4)
        print t, y
    


Answer: While printing `t` and `y` use `plt.scatter(t, y)` After the loop use
`plt.show()`

Or

You can save `t` and `y` in array `T` and `Y` and later use `plt.scatter(T,
Y)` and `plt.show()` to plot.

[![enter image description
here](http://i.stack.imgur.com/qOQzW.png)](http://i.stack.imgur.com/qOQzW.png)

To draw line

    
    
    T, Y = [], []
    

# loop starts

    
    
    ....
    ....
    t = t + h
    y = y + (h / 6.) * (m1 + (2 * m2) + (2 * m3) + m4)
    T.append(t)
    Y.append(y)
    ....
    ....
    

# loop ends

    
    
    plt.plot(T, Y)
    plt.show()
    

[![enter image description
here](http://i.stack.imgur.com/fPxql.png)](http://i.stack.imgur.com/fPxql.png)

