How to use differential equation to solve simple school problem?

52 Views Asked by At

There is simple school programming problem:

If I were on the moon now then my weight would be equals to my_weight * 0.165. Suppose each year of n years my weight grows to 0.4 kg. Thus, I should calculate my weight on moon for each month of there number of years.

I solve the problem with python like this:

import numpy as np
import matplotlib.pyplot as plt
float_formatter = "{:.2f}".format

current_weight = int(input("Enter your current weight: "))
months_weight_rate = float(input("Enter years rate of grows: ")) / 12
months = int(input("Enter number of years: ")) * 12

months_weights = []

for i in range(1, months + 1, 1):
    months_weights.append(float(float_formatter(((current_weight + months_weight_rate) * 0.165))))
    current_weight += months_weight_rate

print(*months_weights)

plt.plot(np.arange(1, months + 1, 1), months_weights)
plt.show()

and have output like this: https://i.stack.imgur.com/3trSY.jpg

My general question is can I use differential equation to solve the problem?

After some search I find out the paper http://math.smith.edu/~callahan/cic/ch4.pdf on the page 3 where is considered diff equation to solve rabbits growth rate problem.

It looks like what I need. But I can't find out how to adapt this equation to solve my problem.