def california_migration_matrix_test ( ): #*****************************************************************************80 # ## california_migration_matrix_test() tests california_migration_matrix(). # # Licensing: # # This code is distributed under the MIT license. # # Modified: # # 19 January 2025 # # Author: # # John Burkardt # import matplotlib.pyplot as plt import numpy as np print ( '' ) print ( 'california_migration_matrix_test():' ) print ( ' Test california_migration_matrix().' ) A = np.array ( [ \ [ 0.70, 0.10 ], \ [ 0.30, 0.90 ] ] ) print ( '' ) print ( ' Year CA Pop US pop Total' ) print ( '' ) m = 21 pop = np.zeros ( [ m, 2 ] ) year = np.linspace ( 1960, 1960 + m - 1, m ) for i in range ( 0, m ): if ( i == 0 ): pop[0,0] = 16000000 pop[0,1] = 164000000 else: pop[i,0:2] = np.matmul ( A, pop[i-1,0:2] ) print ( ' %4d %9.0f %9.0f %9.0f' \ % ( year[i], pop[i,0], pop[i,1], pop[i,0] + pop[i,1] ) ) plt.clf ( ) plt.plot ( year, pop[:,0], linewidth = 3 ) plt.plot ( year, pop[:,1], linewidth = 3 ) plt.grid ( True ) plt.xlabel ( '<-- Year -->' ) plt.ylabel ( '<-- Population -->' ) plt.title ( 'California population matrix' ) plt.legend ( [ 'CA', 'US' ] ) filename = 'california_migration_matrix.png' plt.savefig ( filename ) print ( ' Graphics saved as "' + filename + '"' ) plt.close ( ) return if ( __name__ == "__main__" ): california_migration_matrix_test ( )