Equation for Battery State of Charge

I did not include the following code in the related post.

Took some fooling around but ended up using a sine curve to approximate a state of charge curve I saw on-line.

Here’s the current code used to plot the curve, in module ../calculus/p_p1.py. I also played around using cosine to generate the curve (commented out line in def curve_fn).

# p_p1.py: code for first post, p1, related to geometically visualizing calculus concepts
#   ver 1: 2026.02.01, rek

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns


# Data for plotting
def curve_fn(hrs):
  # start at -np.pi as I want the plot to start at 0, 0
  # add 1 to sine result so goes from 0 to 2 instead of -1 to 1
  # multiply by 0.8 so that sine nevers gets to 0 or 1
  # multiply -np.pi by hour of the day / 12 so that sine input goes from 0 to -2 pi
  #  that is one complete sine cycle
  # multiply by 45 to get a percentage value (range 0 to 2 before muliplication)
  #  and add a touch of asymmetry in upper and lower charge values
  s = ((np.sin(-np.pi * hrs / 12) * 0.8) + 1) * 45
  # s = ((np.cos(np.pi * (hrs+6) / 12) * 0.8) + 1) * 45
  return s

And, yes, that equation could be tied up a little.