I have two arrays:
n = [30, 47.2, 70.2, 77.4, 36.3, 20.6, 18.1, 21.4, 22, 25.4, 27.1, 40.3, 57, 76.6, 52.3, 19.5, 11.2, 7.6, 14.6, 16.2, 24.7]

p = [4, 6.1, 9.8, 35.2, 59.4, 41.7, 19, 13, 8.3, 9.1, 7.4, 8, 12.3, 19.5, 45.7, 51.1, 29.7, 15.8, 9.7, 10.1, 8.6]

and I want to make a plot of the predicted and actual populations based on values I got for a,b,c,d. The way I found my values was that I did least squares fit, but only til the second last number because we were only suppose to find the derivatives of each by doing f(t-1)-f(t)/h
So my values are: -1.4070676691729342, 47.917142857142885, 19.761428571428588, 0.1035338345864648

What I'm having trouble is making the plots.
I don't even get a plot? Please tell me what I'm doing wrong in the following code:
(We are given that n' = n(a-bp) and p' = p(cn-d)

def q(a,b,c,d, themax):
    def f(v,t):

        dn= v[0]*(a-b*v[1])
        dp= (v[1]*(c*v[0]- d))

        #print np.array([dn,dp])
        return np.array([dn,dp]) #solves equations

    times=np.linspace(0,themax,1000)
    v0=np.array([30,4])
    res=odeint(f,v0,times)
    (xvals,yvals)=res.T

    return(xvals,yvals,times)

    (xvals,yvals,times)=q(a,b,c,d,themax)
    plt.plot(times,xvals)
    plt.plot(times,yvals)
    plt.plot(range(len(p)),p)
    plt.plot(range(len(n)),n)
    plt.show()

If you solved it yourself, it is nice of you, if you can post the solution for your thread, so other's can get help from it in future.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.