- #1
SpiffyEh
- 194
- 0
Writing a function problem
If m different species share the same habitat the model becomes a system of recurrent equations:
Ni+1 [1] = Ni [1] + r [1] Ni [1] ( 1 - Ni [1] / K [1] ),
Ni+1 [2] = Ni [2] + r [2] Ni [2] ( 1 - Ni [2] / K [2] ),
……………………………………………………, i = 0, 1, …, i , i + 1, … (2)
Ni+1 [m] = Ni [m] + r [m] Ni [m] ( 1 - Ni [m] / K [m] ).
Lesson 2. Write a C function, NextMany(), that returns Ni+1 for given Ni, r, K for each of m species.
Ok so I know that r and k are 1D m vectors
N - 2D mxn matrix
m - # of species
n - # number of time steps
I don't know why but I'm having a hard time starting this function. So, I understand that I need to take and do the equation n times for each of m species. But how do I pass in the arrays? I know I have to pass in pointers to the function but then I can't remember how to get the size of the array. Also since the N array is mxn and n should only be a value shouldn't it be mx1? or am i storing the Ni +1 in this array?
If m different species share the same habitat the model becomes a system of recurrent equations:
Ni+1 [1] = Ni [1] + r [1] Ni [1] ( 1 - Ni [1] / K [1] ),
Ni+1 [2] = Ni [2] + r [2] Ni [2] ( 1 - Ni [2] / K [2] ),
……………………………………………………, i = 0, 1, …, i , i + 1, … (2)
Ni+1 [m] = Ni [m] + r [m] Ni [m] ( 1 - Ni [m] / K [m] ).
Lesson 2. Write a C function, NextMany(), that returns Ni+1 for given Ni, r, K for each of m species.
Ok so I know that r and k are 1D m vectors
N - 2D mxn matrix
m - # of species
n - # number of time steps
I don't know why but I'm having a hard time starting this function. So, I understand that I need to take and do the equation n times for each of m species. But how do I pass in the arrays? I know I have to pass in pointers to the function but then I can't remember how to get the size of the array. Also since the N array is mxn and n should only be a value shouldn't it be mx1? or am i storing the Ni +1 in this array?