/* Parameter Estimation determining the growth rate r and the carrying capacity.*/ /* Initializations */ dp[1]:0; /*next time population - current time population*/ n :9 ; /*Number of Population data to be considered. Typically taken to be half of the entire given population data.*/ dt: 10 ; /*Time step of the data provided*/ K[1]: 0;/*Carrying capacity computed. It is of length n-2.*/ r1[1]: 0; r2[1]:0 ; /*Arrays containing the rates r1 and r2 corresponding to K[i] and computed based on P[i] and P[i+1] respectively. */ b: 0; c1: 0; c2 : 0; /*Some temp variables introduced.*/ /******************************************/ data: read_matrix("us_population.dat"); disp(transpose(data)[3][1]); p[0]:transpose(data)[3][1]; for i:1 thru n-1 step 1 do (p[i]:transpose(data)[3][i+1], dp[i]: p[i] - p[i-1] ) ; for i:1 thru n-2 step 1 do ( b : (p[i]*dp[i+1] -p[i+1]*dp[i]) , K[i] : (dp[i+1]*p[i]*p[i] - dp[i]*p[i+1]*p[i+1])/b , c1 : dt*( p[i] - p[i]*p[i]/K[i]), r1[i] : dp[i]/c1, c2 : dt*( p[i+1] - p[i+1]*p[i+1]/K[i]), r2[i] : dp[i+1]/c2 ); for i:1 thru n-2 step 1 do (print("time: ", i , " a: ",dp[i+1]*p[i]*p[i] - dp[i]*p[i+1]*p[i+1] , "b: ", p[i]*dp[i+1]-p[i+1]*dp[i], "K: a/b: ", float(K[i])," r values: " ,r1[i]," = ",r2[i] ), print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@") ); /*Plotting the solutions using the parameters obtained above.*/ K : 239.2539884 ; p0:3.929; r:0.0311; population: create_list([1790 + i*10,K*p0/(p0 +(K-p0)*exp(-r*(i*10)))],i,0,15); /*data: read_matrix("us_population.dat");*/ plot2d( [[discrete, transpose(data)[1], transpose(data)[3]],[discrete,population]], [style,points, lines],[point_type,diamond],[color,red , blue] ,[xlabel,"Time"] ,[ylabel,"Population Growth"],[legend, false] ,[title, "Curve Fitting K=239.2539; r=0.0311 "], [legend, "Discrete Population Data" ,"Fitted Curve"], [gnuplot_preamble,"set key bottom"] );