"""Estimate capacitor voltage slope using a centered difference."""
import argparse
import math


def voltage(time):
    return -5 * math.expm1(-time)


def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("time", type=float)
    parser.add_argument("step", type=float)
    inputs = parser.parse_args()
    t, h = inputs.time, inputs.step
    if not (0.25 <= t <= 5 and 0.01 <= h <= 0.25):
        parser.error("Use time in [0.25, 5] s and step in [0.01, 0.25] s.")
    estimate = (voltage(t + h) - voltage(t - h)) / (2 * h)
    exact = 5 * math.exp(-t)
    print(f"Estimate: {estimate:.6f} V/s")
    print(f"Exact: {exact:.6f} V/s")
    print(f"Error: {estimate - exact:.6f} V/s")


if __name__ == "__main__":
    main()
