import tensorflow as tf
import numpy as np
import matplotlib.pyplot as pt
years = np.arange(2000 , 2100)
peoples = np.arange(0 , 100, 1)
people = tf.Variable(10000,dtype=tf.float32)
birthrate = tf.constant(0.018,dtype=tf.float32)
new_people = people+people*birthrate
update = tf.assign(people, new_people)
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
for year in years:
peoples[year-2000]=int(sess.run(people))
sess.run(update)
pt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
pt.rcParams['axes.unicode_minus']=False #用来正常显示负号'
pt.xlim(2000,2100)
pt.ylim(10000,60000)
pt.title("马尔萨斯人口理论")
pt.plot(years,peoples)
pt.show()