当我想减肥的时候,我想起用python科学建模【matplotlib]】
发布日期:2021-05-07 23:08:00 浏览次数:20 分类:精选文章

本文共 1540 字,大约阅读时间需要 5 分钟。

起因

近期因疫情影响,体重居高不下,且每日都有上升的趋势。此情此景我不得不展开减肥大计。于是乎

ing

通过几篇论文的查询,得到了一些公式,将其用python建模得到代码:

import matplotlib.pyplot as pltimport matplotlibimport mathfont = {   'family' : 'MicroSoft YaHei',        'weight': 'bold',        'size': 12}matplotlib.rc('font', **font)weight = float(input('体重:'))height = float(input('身高:'))age = float(input('年龄:'))sex = input('性别:')in_k = float(input('平均每日输入卡路里:'))act = float(input('运动:'))time = float(input('运动时间:'))BMI = float(input('理想BMI:'))day = 0days = []bias = 1base = 0consumes = 0consume = 0while weight*10000/height/height > BMI:# while day < 100:    need_k = 0    if sex == '男':        need_k = 13.88 * weight + 4.16 * height - 3.43 * age + 54.34    else:        need_k = 13.88 * weight + 4.16 * height - 3.43 * age - 58.06    consumes = consume    consume = (need_k + act * time - in_k) * bias    if consume < 0:        print("你的摄入大于消耗,无法减肥")        break    if day != 0:        bias = math.sqrt(consume / consumes) * bias    loose_weight = consume / 7700 * 1.5    weight -= loose_weight    days.append(weight)    day += 1plt.figure(figsize=(20, 10), dpi=80)str_title = '你的'+str(day)+'减肥计划'plt.title(str_title)x_labels = ['{}days'.format(i) for i in range(len(days))]plt.xticks(range(0, len(days), 5), x_labels[::5], rotation=45)plt.yticks(range(40, 80))plt.plot(range(len(days)), days, label='减肥曲线', color='cyan')plt.xlabel('天数')plt.ylabel('体重')plt.grid(alpha=0.99)plt.legend()plt.savefig('loose_weight.png')plt.show()

需要注意,这里的运动是每小时消耗的热量单位【实际上原本是打算按照散步与体重等的关系建模,然鹅没找到公式】

结果

输入:

在这里插入图片描述在这里插入图片描述
好的,减肥计划已生成,可以开始锻炼减肥了。

上一篇:2.4 大电路静态工作点的稳定
下一篇:2.3 放大电路的分析方法

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2025年04月09日 12时14分06秒