Creator of DiceDB, ex-Google Dataproc, ex-Amazon Fast Data, ex-Director of Engg. SRE and Data Engineering at Unacademy. I spark engineering curiosity through my no-fluff engineering videos on YouTube and my courses
You’re working on an smart home temperature control system. The system needs to optimize the comfort. Each room has sensors that measure temperature (T), humidity (H), and occupancy (O). The comfort score (C) of a room is given by the function
C(T, H, O) = 72 - (T - 70)² - 2(H - 40)² + 5O
where T is temperature in Fahrenheit, H is humidity percentage, and O is number of occupants.
Given the current readings of the room as a tuple (T, H, O)
, write Python code to determine which variable should be adjusted first to maximize comfort improvement and whether it should be increased or decreased.
Use the problem statement to dig deeper into the mathematical concept involved and build a practical and deeper understanding. You will also find one 3 Blue 1 Brown video on this topic, must watch for an intuitive understanding.
Inputs:
74, 45, 2
0, 50, 2
500, 50, 2
Output:
humidity, decrease
temperature, increase
temperature, decrease
Here’s the code for reference and some notes on the solution below.
The partial derivatives are:
For your current readings say (T=74°F, H=45%, O=2), let’s run the analysis:
The partial derivatives at the current point are:
Looking at the absolute magnitudes of impact:
This implies - Humidity should be prioritized first because:
So, to maximize comfort improvement:
Arpit's Newsletter read by 125,000 engineers
Weekly essays on real-world system design, distributed systems, or a deep dive into some super-clever algorithm.