<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
        <title>andrewandrade.ca/blog</title>
        <description>andrewandrade.ca/blog - Andrew Andrade</description>
        <link>https://mrandrewandrade.github.io/blog</link>
        <atom:link href="https://mrandrewandrade.github.io/blog/rss.xml" rel="self" type="application/rss+xml" />
        <lastBuildDate>Sat, 29 Nov 2025 14:12:50 +0000</lastBuildDate>
        <pubDate>Sat, 29 Nov 2025 14:12:50 +0000</pubDate>
        <ttl>60</ttl>


        <item>
                <title>Reviving the Blog — Lessons From a Bugle, a Flag, and a Forgotten Story</title>
                <description>&lt;p&gt;It’s been years since I last wrote here. I started this blog back in fourth-year engineering while job hunting—before I joined Palantir, before robotics labs and late-night debugging sessions, before teaching, before all the twists that came after.&lt;/p&gt;

&lt;p&gt;This week, Remembrance Day brought me back.&lt;/p&gt;

&lt;p&gt;I had the honour of playing trumpet with our school band—not the Last Post; I’m still working to be good enough for that—but enough to stand with the group in something meaningful. Instruments in hand, everything paused for a moment, and it pulled me right back to my time in army cadets.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/blog/images/port-credit-boys-george/recruit.jpg&quot; alt=&quot;recruit cadet, sloppy uniform, looking lost&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Even now, that first year is burned into my memory—awkward uniform, barely any badges, trying to figure out what leadership meant.  Luckily we had mentors to guide us!&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/blog/images/port-credit-boys-george/mentors.jpg&quot; alt=&quot;mentors have badges, we have empty sleeves with no badges&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Cadets taught me that rank wasn’t the patch; it was the work behind it.&lt;/p&gt;

&lt;p&gt;As we approached Remembrance Day this year, I found myself thinking about the small rituals that shaped me. Raising the flag was one of them.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/blog/images/port-credit-boys-george/raise_1.jpg&quot; alt=&quot;standing by the flagpole — photo 1&quot; /&gt;
&lt;img src=&quot;/blog/images/port-credit-boys-george/raise_2.jpg&quot; alt=&quot;standing by the flagpole — photo 2&quot; /&gt;&lt;br /&gt;
&lt;img src=&quot;/blog/images/port-credit-boys-george/raise_3.jpg&quot; alt=&quot;standing by the flagpole — photo 3&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Sometimes it was early, cold, or rushed—but it mattered. And I wasn’t alone.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/blog/images/port-credit-boys-george/friends.jpg&quot; alt=&quot;standing with friends, guilty smile, preparing flags&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Music also became part of those mornings, including our national anthem.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/blog/images/port-credit-boys-george/playing_trumpet.jpg&quot; alt=&quot;Insert photo: playing trumpet as a private&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Fast-forward to high school robotics, coding, and engineering—different worlds entirely, but the same threads of discipline and responsibility ran through them.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/blog/images/port-credit-boys-george/attention.jpg&quot; alt=&quot;standing at attention in the band&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I didn’t stay long enough in cadets to stack up badges like the mentors I admired, but the two years I spent there were full. Varied, intense, and formative, but I still loved computers.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/blog/images/port-credit-boys-george/corp_1.jpg&quot; alt=&quot;on the computer — arm 1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/blog/images/port-credit-boys-george/corp_2.jpg&quot; alt=&quot;on the computer — arm 1&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This year, as part of preparing for our ceremony, I learned more than I expected—thanks entirely to the Student Activity Council, who did all the research.&lt;br /&gt;
That’s where I discovered the story of &lt;strong&gt;George Cardozo&lt;/strong&gt;, one of the “Port Credit Boys.”&lt;/p&gt;

&lt;h1 id=&quot;the-bugler-they-didnt-let-become-an-officer&quot;&gt;The Bugler They Didn’t Let Become an Officer&lt;/h1&gt;

&lt;p&gt;George’s story starts decades before mine, but strangely close to home.&lt;/p&gt;

&lt;p&gt;He was a Jamaican-born teacher, educated in Port-au-Prince and Kingston, who came to Canada and enlisted with the 4th Battalion, Canadian Expeditionary Force, on 22 September 1914.&lt;/p&gt;

&lt;p&gt;One of the first recruits at Valcartier.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/blog/images/port-credit-boys-george/standing.jpg&quot; alt=&quot;George Standing&quot; /&gt;)&lt;/p&gt;

&lt;p&gt;His attestation paper recorded only the essentials: his trade or calling, his date of birth, and his place of birth. Beyond those brief entries, the rest of George’s life, identity, and service must be reconstructed through the surviving evidence gathered from archival and family research. A fuller picture — his experiences as a Jamaican-born bugler, his movement through the Canadian Expeditionary Force, and the context surrounding his enlistment — comes from the sources compiled in the project’s research. These include &lt;strong&gt;My Jamaican Family&lt;/strong&gt;’s biography &lt;a href=&quot;https://myjamaicanfamily.blogspot.com/2014/11/rembering-george-cardozo-1890-1915.html&quot;&gt;&lt;em&gt;They Shall Grow Not Old – George Cardozo, a Casualty of …&lt;/em&gt;&lt;/a&gt; and &lt;a href=&quot;https://myjamaicanfamily.blogspot.com/2014/11/rembering-george-cardozo-1890-1915.html&quot;&gt;&lt;em&gt;Remembering George Cardozo, 1890–1915&lt;/em&gt;&lt;/a&gt;, the &lt;strong&gt;Canadian Virtual War Memorial&lt;/strong&gt; entry for &lt;a href=&quot;https://www.veterans.gc.ca/en/remembrance/memorials/canadian-virtual-war-memorial/detail/922681&quot;&gt;&lt;em&gt;George Cordozo&lt;/em&gt;&lt;/a&gt; from &lt;strong&gt;Veterans Affairs Canada&lt;/strong&gt;, and his digitized service file in &lt;strong&gt;Library and Archives Canada&lt;/strong&gt;’s &lt;a href=&quot;https://www.canada.ca/en/library-archives/collection/research-help/military-history/first-world-war/fww-personnel.html?wbdisable=true&amp;amp;utm_source=chatgpt.com&quot;&gt;&lt;em&gt;Personnel Records of the First World War&lt;/em&gt;&lt;/a&gt;. Together, these sources allow us to understand George far more deeply than the minimal information captured on the photo.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/blog/images/port-credit-boys-george/attestation.jpg&quot; alt=&quot;George&apos;s attestation paper&quot; /&gt;&lt;/p&gt;

&lt;p&gt;According to Dorothy Kew from the  My Jamaican Family Blog, he was:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Five foot five&lt;/li&gt;
  &lt;li&gt;Dark complexion&lt;/li&gt;
  &lt;li&gt;“Coloured”&lt;/li&gt;
  &lt;li&gt;Roman Catholic&lt;/li&gt;
  &lt;li&gt;Teacher&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With his education and background, he should have been an officer.&lt;br /&gt;
But because of his colour, he wasn’t given that chance.&lt;/p&gt;

&lt;p&gt;Instead, they made him a &lt;strong&gt;bugler&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/blog/images/port-credit-boys-george/sitting.jpg&quot; alt=&quot;George Sitting&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Today, the role is ceremonial.&lt;br /&gt;
Back then, buglers woke before everyone else, played Reveille in the cold, roused officers, and handled the morning chores no one else wanted.&lt;/p&gt;

&lt;p&gt;George still trained hard—at Ravina Barracks, on the SS &lt;em&gt;Tyrolia&lt;/em&gt; to England, and finally to the Western Front.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/blog/images/port-credit-boys-george/pc_boys.jpg&quot; alt=&quot;Port Credit Boys&quot; /&gt;&lt;/p&gt;

&lt;p&gt;He died sometime between April 22–26, 1915, during the Second Battle of Ypres—the first time poison gas was used in the Great War. His body was never found.&lt;br /&gt;
His name is carved on the Menin Gate Memorial in Belgium with over 55,000 others who have no known grave.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/blog/images/port-credit-boys-george/grave_george.jpg&quot; alt=&quot;Grave&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Every evening at 8 p.m., beneath his name, &lt;strong&gt;they still sound the Last Post&lt;/strong&gt;.&lt;/p&gt;

&lt;h1 id=&quot;bugles-flags-and-the-things-we-carry-forward&quot;&gt;Bugles, Flags, and the Things We Carry Forward&lt;/h1&gt;

&lt;p&gt;This year I raised my trumpet high,&lt;/p&gt;

&lt;p&gt;Not for the Last Post’s mournful cry,&lt;/p&gt;

&lt;p&gt;But with a deeper, steadier sight&lt;/p&gt;

&lt;p&gt;Of all the threads that shaped my flight.&lt;/p&gt;

&lt;p&gt;I thought of flags I used to raise,&lt;/p&gt;

&lt;p&gt;The badges missed in younger days,&lt;/p&gt;

&lt;p&gt;The mentors’ paths I didn’t tread,&lt;/p&gt;

&lt;p&gt;And those who served and marched instead.&lt;/p&gt;

&lt;p&gt;I thought of George—so much like me—&lt;/p&gt;

&lt;p&gt;A teacher-learner meant to be,&lt;/p&gt;

&lt;p&gt;Who left to fight through smoke and flame&lt;/p&gt;

&lt;p&gt;And never made it home again.&lt;/p&gt;

&lt;h1 id=&quot;we-remember&quot;&gt;We Remember&lt;/h1&gt;

&lt;blockquote&gt;
  &lt;p&gt;“They shall grow not old, as we that are left grow old…”&lt;br /&gt;
— &lt;em&gt;For the Fallen&lt;/em&gt;, Lawrence Binyon&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This post is both a return and a reminder—of the past we inherit, the stories we uncover, and the unexpected ways they shape our present.&lt;/p&gt;

&lt;p&gt;This Remembrance Day, I played the trumpet for our school.&lt;br /&gt;
But I also played it for George.&lt;/p&gt;

&lt;p&gt;And I’m honoured to remember him here.&lt;/p&gt;
</description>
                <link>https://mrandrewandrade.github.io/blog/2025/11/13/remembering-the-port-credit-boys.html</link>
                <guid>https://mrandrewandrade.github.io/blog/2025/11/13/remembering-the-port-credit-boys</guid>
                <pubDate>Thu, 13 Nov 2025 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>Generalized Solution to Multi-Echelon Inventory Decisions</title>
                <description>&lt;p&gt;This post outlines the generalized solution to Multi-Echelon Inventory Decisions by finding the lower, upper and average bound for an optimal solution.  It then outlines a genetic algorithm approach to finding the optimal solution.  The generalized solution procedure is applied to the &lt;a href=&quot;http://ptgmedia.pearsoncmg.com/images/9780133757880/samplepages/0133757889.pdf&quot;&gt;Multi-Echelon Inventory 
Decisions at Jefferson 
Plumbing Supplies
To Store or Not to Store?&lt;/a&gt; Case Study&lt;/p&gt;

&lt;h1 id=&quot;introduction&quot;&gt;Introduction:&lt;/h1&gt;

&lt;p&gt;Alex, a NASCAR enthusiast, is the Inventory Manager of Jefferson
Plumbing Supplies, and he faces an interesting quandary. He has been
notified by one of his suppliers that there is an upcoming increase to
their minimum order quantity. The following case study summary presents
a description, a system model, and a summary and conclusion for the
problem Alex faces.&lt;/p&gt;

&lt;h1 id=&quot;problem&quot;&gt;Problem:&lt;/h1&gt;

&lt;p&gt;Jefferson Plumbing has know demand of 100 units annually, from loyal
customers, of a specialty faucet that is ordered from a long time
supplier. Alex received a letter from the supplier informing him that
they would be increasing their minimum order quantity. The new minimum
order quantity is triple what would normally be ordered. Due to their
storefront’s city location, inventory holding costs for the faucet are
expensive. Jefferson Plumbing Supplies has a warehouse with a cheaper
annual holding cost, and Alex would like to determine the optimum costs
previous to, and after the policy change.&lt;/p&gt;

&lt;h2 id=&quot;options&quot;&gt;Options:&lt;/h2&gt;

&lt;p&gt;1. convince the company to maintain relations to drop the minimum order
amount&lt;/p&gt;

&lt;p&gt;2. not stock the item -&amp;gt; lost revenue and customers&lt;/p&gt;

&lt;p&gt;3. order and store in the store&lt;/p&gt;

&lt;p&gt;4. order and store in the storage facility (multi-echelon system)&lt;/p&gt;

&lt;p&gt;5. find alternative storage&lt;/p&gt;

&lt;p&gt;Given that option 1, 2, and 5 are not feasible there is option 3 (the
base case) and option 4.&lt;/p&gt;

&lt;h2 id=&quot;variables&quot;&gt;Variables&lt;/h2&gt;

&lt;p&gt;Holding cost h &lt;span&gt;[&lt;/span&gt;$ unit/time&lt;span&gt;]&lt;/span&gt;&lt;br /&gt;
Stockout Penalty p &lt;span&gt;[&lt;/span&gt;$/unit/time &lt;span&gt;]&lt;/span&gt;&lt;br /&gt;
Fixed Cost k &lt;span&gt;[&lt;/span&gt;$/order &lt;span&gt;]&lt;/span&gt;&lt;br /&gt;
Purchase cost c &lt;span&gt;[&lt;/span&gt;$/ unit &lt;span&gt;]&lt;/span&gt;&lt;br /&gt;
Demand λ &lt;span&gt;[&lt;/span&gt;units/time &lt;span&gt;]&lt;/span&gt;&lt;br /&gt;
Order quantity Q &lt;span&gt;[&lt;/span&gt;units &lt;span&gt;]&lt;/span&gt;&lt;br /&gt;
Optimal order quantity Q* &lt;span&gt;[&lt;/span&gt;units&lt;span&gt;]&lt;/span&gt;&lt;br /&gt;
Re-order interval u &lt;span&gt;[&lt;/span&gt; time&lt;span&gt;]&lt;/span&gt;&lt;br /&gt;
Average Annual Cost C(Q) &lt;span&gt;[&lt;/span&gt;$/year&lt;span&gt;]&lt;/span&gt;&lt;br /&gt;
Optimal order quantity C* =C(Q*) &lt;span&gt;[&lt;/span&gt;units&lt;span&gt;]&lt;/span&gt;\&lt;/p&gt;

&lt;h2 id=&quot;assumptions&quot;&gt;Assumptions:&lt;/h2&gt;

&lt;p&gt;Assumption given in case study:\&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Continuous deterministic demand of λ = 100 units/year&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;2. The cost of not having inventory is very high (lost of profit and
lost of customers and future profit)&lt;/p&gt;

&lt;p&gt;3. Minimum order quantity \(Q_{min} = 130\) units, previous order quantity
was about 130/3 units 4. No capacity limits 5. Must always have positive
inventory (no backorders) based on assumption 2&lt;/p&gt;

&lt;p&gt;Assumptions taken to relax problem:\&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;No lead time&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;2. Purchase cost c is ignored in optimization as it remains constant&lt;/p&gt;

&lt;p&gt;3. The holding cost includes the cost of held capital (no interest rate)&lt;/p&gt;

&lt;h2 id=&quot;givens&quot;&gt;Givens:&lt;/h2&gt;

&lt;p&gt;Purchase Fixed ording cost \(k_p = \$100/order\)&lt;/p&gt;

&lt;p&gt;Warehouse ordering cost \(k_w = \$50/order\)&lt;/p&gt;

&lt;p&gt;Store holding cost \(h_s = \$10/unit/year\)&lt;/p&gt;

&lt;p&gt;Warehouse hoding cost \(h_w =  \$1/unit/year\)&lt;/p&gt;

&lt;h1 id=&quot;system-model&quot;&gt;System model:&lt;/h1&gt;

&lt;h2 id=&quot;base-case-deterministic-economic-order-quantity-model&quot;&gt;Base Case: Deterministic Economic Order Quantity Model&lt;/h2&gt;

&lt;p&gt;In the base case, the system can be modeled as a simple single order
system where the quantity is stored at the retail store.&lt;/p&gt;

&lt;p&gt;Manufacturer -&amp;gt; Retailer&lt;/p&gt;

&lt;p&gt;Using a basic economic order quantity (EOQ) model and the assumptions
previously made, the yearly cost of the base case would be:&lt;/p&gt;

\[C(Q) = \frac{k_p \lambda}{Q} + \frac{h_s Q}{2}\]

&lt;p&gt;Given the first order condition:&lt;/p&gt;

\[\frac{\partial C} {\partial Q}  =  - \frac{k_p \lambda}{Q^2} + \frac{h_s}{2} = 0\]

&lt;p&gt;Given this is a local minimum, the optimal quantity would be:&lt;/p&gt;

\[Q^* = \sqrt{\frac{2 k_p \lambda}{h_s}} = 44.72135955 = 45 units\]

&lt;p&gt;With the optimal annual cost would be:&lt;/p&gt;

\[C^* =  C(Q^*) = \sqrt{2 \lambda k_p h_s}  \cong \$447.21\]

&lt;p&gt;Since the minimum order quantity \(Q_{min} \ge 130\) as stated in the
problem and the actual optimal annual cost would be:&lt;/p&gt;

\[C(Q_{min}) = \frac{k_p \lambda}{Q_{min}} + \frac{h_s Q_{min}}{2} \cong \$726\]

&lt;p&gt;The annual cost is convex optimum, therefore the smallest minimum order
quantity would be optimal in this model.&lt;/p&gt;

&lt;h2 id=&quot;two-stage-deterministic-multi-echelon-serial-system&quot;&gt;Two stage deterministic multi-echelon serial system&lt;/h2&gt;

&lt;p&gt;An alternative system model would be two stage: after an order is placed
from the manufacturer it would be stored at a lower cost in the
warehouse and be shipped to the retailer. In shematic form:&lt;/p&gt;

&lt;p&gt;Manufacturer -&amp;gt; Warehouse -&amp;gt; Retailer&lt;/p&gt;

&lt;p&gt;Each stage functions like an EOQ system and determines the optimal order
quantity and period. Solution will have a zero inventory ordering
(ordering will occur when inventory is zero) assuming no lead time.&lt;/p&gt;

&lt;p&gt;Since the minimum order quantity is greater than yearly demand,
therefore there will only be a maximum of 1 order within a year from the
manufacturer. The initial assumption will be made that it is cheaper to
store inventory at the warehouse and order parts when required. This
assumption will be later verified by comparing the total cost to the
base case.&lt;/p&gt;

&lt;p&gt;We are going to introduce the reorder interval \(\textbf{u} = Q /
\lambda\), and can be thought of as a vector for each stage (j) of the
ordering process. In our case, \(u_w\) is the ordering period made &lt;strong&gt;at&lt;/strong&gt;
the warehouse &lt;strong&gt;from the store&lt;/strong&gt; and \(u_p\) is the ordering period &lt;strong&gt;at
the production factory&lt;/strong&gt; from the warehouse.&lt;/p&gt;

&lt;p&gt;The averaged annual cost function (to be minimized) of the most ideal
function would be the following:&lt;/p&gt;

\[C (\textbf{u}) =  \sum_{j} \left(\frac{k_j}{u_j}+ \frac{h_j \lambda u_j}{2}\right) = \frac{k_w}{u_w}+ \frac{(h_s -h_w)\lambda u_w}{2} + \frac{k_p}{u_p}+ \frac{h_w \lambda u_p}{2}\]

&lt;p&gt;Such that:&lt;/p&gt;

\[u_j = \theta_j u_{j+1},\]

\[u_j \ge 0,\]

\[\theta_j  \in \mathbb{Z}^+ =  \{1, 2, 3, ...\}\]

&lt;p&gt;There is also the added constraint due to the minimum quantity order for
$u_p$&lt;/p&gt;

\[u_p \ge \frac{Q_{min}}{\lambda} = \frac{13}{10}\]

&lt;p&gt;Solving this optimization problem for the optimum reorder interval
\(\textbf{u*}\) leads to a non-convex mixed integer non-linear
programming. Since the constrained solution is non-convex, it does not
have a guaranteed optimal solution except in limit. For this reason, a
generalized approach to finding the lower, upper and mean average annual
cost must be used.&lt;/p&gt;

&lt;h2 id=&quot;generalized-solution&quot;&gt;Generalized Solution:&lt;/h2&gt;

&lt;p&gt;The generalized solution to an non-convex, mixed interger non-linear
programming optimization problem is to get an upper bound by solving a
relaxed problem (non-interger constraint) which represents the worst
cast scenario.&lt;/p&gt;

&lt;p&gt;The relaxed optimization problem is the following:&lt;/p&gt;

\[C (\textbf{u}) =  \sum_{j} \left(\frac{k_j}{u_j}+ \frac{h_j \lambda u_j}{2}\right) = \frac{k_w}{u_w}+ \frac{h_s \lambda u_w}{2} + \frac{k_p}{u_p}+ \frac{h_w \lambda u_p}{2}\]

&lt;p&gt;Such that:&lt;/p&gt;

&lt;p&gt;\(u_j \ge u_{j+1}\) \(u_j \ge 0\)
\(u_p \ge \frac{Q_{min}}{\lambda} = \frac{13}{10}\)&lt;/p&gt;

&lt;p&gt;This can be solved using multi-variate calculus or [numerically]&lt;/p&gt;

&lt;p&gt;Using calculus, the partial derivative of the cost function with respect
to \(u_p\) can be taken as:&lt;/p&gt;

\[\frac{\partial}{\partial u_p}(\frac{k_w}{u_w}+ \frac{h_s \lambda u_w}{2} + \frac{k_p}{u_p}+\frac{h_w \lambda u_p}{2})= \frac{\lambda  h_w}{2}- \frac{k_p}{u_p^2}\]

&lt;p&gt;Now solving for $u_p$&lt;/p&gt;

\[u_p^*  = ±\frac{\sqrt{\frac{2k_p}{h_w}} }{\sqrt{\lambda}} = \sqrt{2} \ge \frac{13}{10}\]

&lt;p&gt;Similarly, the partial derivative of the cost function with respect to
\(u_w\) can be taken as:&lt;/p&gt;

\[\frac{\partial}{\partial u_w}(\frac{k_w}{u_w}+ \frac{h_s \lambda u_w}{2} + \frac{k_p}{u_p}+ \frac{h_w \lambda u_p}{2})= \frac{h_s \lambda}{2}-\frac{k_w}{u_w^2}\]

&lt;p&gt;Now solving for $u_w$&lt;/p&gt;

\[u_w^* = ±  \frac{\sqrt{2 k_w}}{\sqrt{h_s \lambda}} = \frac{\sqrt{10}}{10}\]

&lt;p&gt;The upper bound of the overall cost function can now be calculated as:&lt;/p&gt;

\[C_* = C(\textbf{u*}) \ge 100(\sqrt{2} + \sqrt{10}) \cong 457.649122254\]

&lt;p&gt;In this case, about every 1.414 years the warehouse would order:&lt;/p&gt;

\[Q_p^* = u_p \lambda = 100 \sqrt{2} \cong 141.421 = 142 units\]

&lt;p&gt;The retail store would order:&lt;/p&gt;

\[Q_w^* = u_w \lambda = 100 \sqrt{10} \cong 31.522 =  32 units\]

&lt;p&gt;This would result in the overall cost to be:&lt;/p&gt;

\[C(\textbf{Q}) = \frac{129979}{284} \cong \$457.67\]

&lt;p&gt;Using the same approach using the un-relaxed cost function (and assuming
incorrectly an optimal solution), the optimal order quantities becomes:&lt;/p&gt;

\[Q_p^* = u_p \lambda = 100 \sqrt{2} \cong 141.421 = 142 units\]

&lt;p&gt;The retail store would order:&lt;/p&gt;

\[Q_w^* = u_w \lambda = 100/3 \cong  33.33 =  34 units\]

&lt;p&gt;This results in the following approximate ideal average annual cost
\(C(\textbf{Q})_{ideal} \cong\) &lt;a href=&quot;http://www.wolframalpha.com/input/?i=%2850%29%2F%28x%29+%2B+%289+*+100+*+x%29%2F%282%29+%2B+%28100%29%2F%28y%29%2B+%281+*+100+*+y%29%2F%282%29%2C+x+%3D+0.34%2C+y+%3D+1.42&quot;&gt;$441.81&lt;/a&gt; This lower bound would be
better estimated by evaluating the cost of storing the remaining
inventory in the warehouse. For example, after the first order cycle of
142 parts from the supplier and first three shipments to the store,
there will be 14 parts remaining. At a cost of $1 per year per item,
this also adds a $14 cost over the three cycles. In the next cycle
(order the minimum quantity of 130 units), there will be 16 left over.
This continues by units of 2 (over 30 cycles) until 30 units and then
finally there will be no remain parts and the cycle starts again. This
means over 30 order cycles from the store to the warehouse, we would
face a mean unit period cost of 198 units * $1 /30 or $6.6 per order
cycle. This means the actual lower bound of the solution is around
448.41. The difference between the upper and ideal lower bound of the
solution is around $16.19 or the price of a beer and a Speedway Big Hog
Chedder Dog at a Nascar event and the approximate average annual cost
would sit closer to $448.41. Since the optimal order quantity from the
warehouse is \(Q_w* = 34\) units,
\(\theta_{theoretical}^* = Q_w^* / Q_p^* \cong 4.176470588\) and
\(\theta_{actual}^* = 4\). Since the difference between
\(\theta_{theoretical}^*\) and \(\theta_{actual}^*\) is small, the actual
solution would be much closer to the lower bound.&lt;/p&gt;

&lt;h1 id=&quot;constrained-optimization-solution&quot;&gt;Constrained Optimization Solution&lt;/h1&gt;

&lt;p&gt;To improve upon the generalized approach and attempt to find the true
optimal solution, the optimization problem can be solved using a
non-linear programming tool such as Goal Seek in Excel, as demonstrated in this &lt;a href=&quot;https://andrewandrade.ca/blog/images/case-study.xls&quot;&gt;spreadsheet&lt;/a&gt;. Alternatively,
the lower bound of the optimal solution can be estimated &lt;a href=&quot;http://www.wolframalpha.com/input/?i=minimize+%2850%29%2F%28x%29+%2B+%2810+*+100+*+x%29%2F%282%29+%2B+%28100%29%2F%28y%29%2B+%281+*+100+*+y%29%2F%282%29+such+that+x%3E+0+%2C+y+%3E+13%2F10&quot;&gt;numerically&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;or using calculus. Then $\theta_j$ can be calculated and rounded to find
the order quantities (as shown in the generalized solution).&lt;/p&gt;

&lt;p&gt;The results from both methods are in agreement and the result in
$Q_w^* = 34$, $Q_p^*= 136$ and an overall average annual cost of about
$441.59 which is $5.62 dollars cheaper than before the policy change.&lt;/p&gt;

&lt;h1 id=&quot;summary&quot;&gt;Summary and Conclusion&lt;/h1&gt;

&lt;h2 id=&quot;optimum-cost-before-policy-change&quot;&gt;Optimum Cost before policy change&lt;/h2&gt;

&lt;p&gt;The optimum annual cost before the policy change in the problem is
$447.21/year&lt;/p&gt;

&lt;h2 id=&quot;optimum-cost-ordering-and-storing-to-retail-store-alone&quot;&gt;Optimum Cost Ordering and Storing to Retail Store Alone&lt;/h2&gt;

&lt;p&gt;Given the assumptions in this problem, using the optimum solution of a
basic EOQ model results in an optimum ordering 130 units (when stock
reaches zero), results in an actual optimal annual cost of around $726&lt;/p&gt;

&lt;p&gt;This means that this would cost the store about $277.79 more if they
choose to order, ship and store to the retail store.&lt;/p&gt;

&lt;h2 id=&quot;optimum-cost-using-a-warehouse&quot;&gt;Optimum Cost Using a Warehouse&lt;/h2&gt;

&lt;p&gt;Given the assumptions in this problem, the approximate optimum solution
of the two stage deterministic multi-echelon serial system provides an
annual cost of around $447.21. This means that the policy change would
cost the store at most about $5.61 less if they order 144 parts to the
warehouse and 136 parts from the warehouse to the retail store. Alex
Halek wwould be able to rest at ease and possibly use those savings
towards the purchase of a delicious Speedway Big Hog Cheddar Dog at next
year’s Spring Cup.&lt;/p&gt;

</description>
                <link>https://mrandrewandrade.github.io/blog/2016/02/16/generalized-solution-to-multi-echelon-inventory-decisions.html</link>
                <guid>https://mrandrewandrade.github.io/blog/2016/02/16/generalized-solution-to-multi-echelon-inventory-decisions</guid>
                <pubDate>Tue, 16 Feb 2016 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>Production and Operations Management 101 Reference Sheet</title>
                <description>&lt;h1 id=&quot;learning-curve&quot;&gt;Learning Curve&lt;/h1&gt;

&lt;p&gt;Given Y(u) is the number of time units to produce the uth unit, then using $$Y(u) = au^{-b}&lt;/p&gt;

&lt;p&gt;Now to describe the % decline in labour hours to produce 2n compared to hours required to produce item 2n compaures to the hours required to produce item n:&lt;/p&gt;

\[\frac{Y(2u)}{Y(u)} = \frac{a (2u)^{-b}}{a (u)^{-b}} = 2^{-b}\]

&lt;p&gt;Since 80% is a historically determined learning curve, \(2^{-b} = 0.8\):
\(b = \frac{-ln 0.8}{ln 2} = 0.322\)&lt;/p&gt;

&lt;h1 id=&quot;timing-capacity-additions&quot;&gt;Timing Capacity Additions&lt;/h1&gt;

&lt;p&gt;D = annual increase in demand, x = time intervals between capacity additions, r = annual discount rate (compounded continously), f(y) = cost of operating a plant of capacity y.  Now given C(x) is the total discounted cost of all capacity additions over an infinite horizon, if new plants are built even x units of time:&lt;/p&gt;

&lt;p&gt;$$ C(x) = \frac{f(xD)}{(1-e^{-rx}}&lt;/p&gt;

&lt;p&gt;TODO: Understand the next equations better, before writing them here.&lt;/p&gt;

&lt;h1 id=&quot;inventory-control-under-known-demand&quot;&gt;Inventory Control Under Known Demand&lt;/h1&gt;

&lt;p&gt;Holding or Carrying cost (\(h = Ic\)) where h is the holding cost, I is the annual interest rate, and c is the $ per unit of inventory.&lt;/p&gt;

</description>
                <link>https://mrandrewandrade.github.io/blog/2016/01/16/production-operations-management.html</link>
                <guid>https://mrandrewandrade.github.io/blog/2016/01/16/production-operations-management</guid>
                <pubDate>Sat, 16 Jan 2016 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>Thermodynamics 101 Reference Sheet</title>
                <description>&lt;h1 id=&quot;assumptions-and-common-terms&quot;&gt;Assumptions and Common Terms&lt;/h1&gt;

&lt;p&gt;First lets start with some common assumptions (refer back here when they come up):&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Kinetic and potential energy remains about constant (\(\Delta KE, \Delta PE ~= 0\))&lt;/li&gt;
  &lt;li&gt;Isobaric (pressure is constant)&lt;/li&gt;
  &lt;li&gt;Isothermal (temperature is constant)&lt;/li&gt;
  &lt;li&gt;Isovolumetic (total volume (V) is constant)&lt;/li&gt;
  &lt;li&gt;Rigid (change in volume is zero or \(dV = 0\))&lt;/li&gt;
  &lt;li&gt;Adiabatic (heat transfer is zero or \(\dot Q = 0\)&lt;/li&gt;
  &lt;li&gt;Reversible (\(\dot P_s = 0\))&lt;/li&gt;
  &lt;li&gt;Ideal Gas more below&lt;/li&gt;
  &lt;li&gt;stead-state or SS (change is zero or d/dt = 0)&lt;/li&gt;
  &lt;li&gt;steady flow or SD (\(U_{IN}, h_{IN},\) … = constant)&lt;/li&gt;
  &lt;li&gt;Liquids and solids have constant volume&lt;/li&gt;
  &lt;li&gt;Liquids are solids are assumed incompressible&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Next lets learn some commons terms (refer back here when they come up):&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;compressed liquid&lt;/strong&gt; or &lt;strong&gt;subcooled liquid&lt;/strong&gt;: fluid in liquid phase and not about to vaporize.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;saturated liquid&lt;/strong&gt;: liquid about to vaporize&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;saturated vapour&lt;/strong&gt;: vapor about to condense&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;saturated (liquid-vapor) mixture:&lt;/strong&gt; liquid and vapor phases co-existing in equilibrium.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;super heated vapor&lt;/strong&gt;: vapor not about to condense&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;saturation temperature&lt;/strong&gt;: temperature at which a pure substance changes phase&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;saturation pressure&lt;/strong&gt;: pressure at which a pure substance change phase&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;critical point&lt;/strong&gt;: point where thje saturated liquid and saturated vapour states are the same&lt;/p&gt;

&lt;h1 id=&quot;laws&quot;&gt;Laws&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;zero law of thermodynamics:&lt;/strong&gt;
if two seperate bodies are in thermo equilibrium with a third, they the first two are in equilibrium. (think of the third body as a thermometer and the first two as non conected bodies)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;first law of thermodynamics:&lt;/strong&gt;&lt;br /&gt;
chance in energy of system = energy into system - energy out of system + energy produced by system&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;concervation of mass:&lt;/strong&gt;
change in mass of system =  mass into system - mass out of system + mass produced by system.&lt;/p&gt;

&lt;p&gt;Note: both the mass produced and energy produced by system is usually equal to zero.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;second law of thermodynamics:&lt;/strong&gt;
energy has &lt;em&gt;quality&lt;/em&gt; in addition to having a &lt;em&gt;quantity&lt;/em&gt; (more about that later)&lt;/p&gt;

&lt;h1 id=&quot;properties&quot;&gt;properties&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;primary/fundamental properties:&lt;/strong&gt;
basic dimentions which describe the universe as we know it (length, mass, time, temperature, electic current, amount of light, amount of matter)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;secondary properties:&lt;/strong&gt;
properties derived from the fundamental properties (ie velocity = displacement/time)&lt;/p&gt;

&lt;h3 id=&quot;mass&quot;&gt;Mass&lt;/h3&gt;

&lt;p&gt;I am not going to go into what mass is.  It relates to gravitational attraction and
\(E = m c^2\)&lt;/p&gt;

&lt;p&gt;Its measured in grams in the SI system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; unity conversion ratio
There is a difference between lbm pound mass (slug) and pound force lbf in the imperial system&lt;/p&gt;

&lt;p&gt;pound mass or slug is the mass which accelerates by 1 ft/s when the force of one pound is exerted on it&lt;/p&gt;

\[1 lbf = 32.174 lbm * ft/s^2\]

&lt;h3 id=&quot;force&quot;&gt;Force&lt;/h3&gt;
&lt;p&gt;Force (F) is mass times acceleration or pressure times area, measured in newtons.&lt;/p&gt;

\[F = P A = m g\]

&lt;p&gt;Pressure is force divided by area and is measured in Pascals or Pa.&lt;/p&gt;

\[1 Pa = 1 \frac{N}{m^2} = 1 \frac{kg}{m \times s^2}\]

&lt;p&gt;Note: &lt;strong&gt;absolute pressure&lt;/strong&gt; is measured in an absolute vacuum (absolute zero pressure) and &lt;strong&gt;guage pressure&lt;/strong&gt; is relative to atmosphere.  &lt;strong&gt;Vacuum pressures&lt;/strong&gt; are when a pressure is less than atmosphere.  Mathematically this means:&lt;/p&gt;

\[P_{gage} = P_{abs} - P_{atm} = \rho g h\]

\[P_{vac} = P_{atm} - P_{abs}\]

&lt;p&gt;PSI is pressure measured in pounds per square inch.  PSIg is measuring guage pressure, PSIa is measuring absolute pressure.&lt;/p&gt;

&lt;p&gt;Pressure can also be measured from the following equations:&lt;/p&gt;

\[P = P_{gage} + P_{atm}\]

\[\Delta P = P_2 - P_1 = - \int \rho g dz\]

&lt;p&gt;There are a bunch of devices with measure pressure, just look them up if ever you have to use them.&lt;/p&gt;

&lt;p&gt;Pressure is the same in any fluid measured at the same depth.  Read the book, it explains it.&lt;/p&gt;

&lt;h2 id=&quot;types-of-properties&quot;&gt;types of properties&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;intensive property&lt;/strong&gt; independant of mass/volume (temperature, pressure, density)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;extensive propety&lt;/strong&gt; property dependant on size of system (mass, volume)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;specific property&lt;/strong&gt; extensive property per unit mass (just divide by mass)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;volume&lt;/strong&gt; I am using the following symbol for volume:&lt;/p&gt;

\[\vee\]

&lt;p&gt;&lt;strong&gt;density&lt;/strong&gt;  mass per unit volume&lt;/p&gt;

\[\rho = \frac {m}{ \vee }\]

&lt;p&gt;&lt;strong&gt;weight is a force&lt;/strong&gt;
\(W = mg\) (Newtons)&lt;/p&gt;

&lt;p&gt;Where m is mass, and g is the acceleration due to gravity&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;specific weight&lt;/strong&gt; is density times acceleration due to gravity
\(\gamma = \rho g\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;specific volume&lt;/strong&gt; is volume per unit mass&lt;/p&gt;

\[\nu = \frac{\vee}{m} = \frac{1}{\rho}\]

&lt;p&gt;specific gravity or relative density is the ratio of the density of a substance to the density of some standard substance at a specified temperature (ususally water at 4 degress C where the density is 1000 kh/m^3)&lt;/p&gt;

\[SG = \frac{\rho}{\rho_{H_2 O}}\]

&lt;h2 id=&quot;state-postulate&quot;&gt;State Postulate&lt;/h2&gt;

&lt;p&gt;Okay now we now that we can use properties to descripte the state of a system  The thing is we don’t need to specify &lt;em&gt;all&lt;/em&gt; the properties to fix a state.  This means if we define a sufficient number of properties, then we can determine the rest. As a different example if we know the distance and time someone traveled, we can determine their average velocity.  In the same way if we have two &lt;em&gt;independant&lt;/em&gt; properties, then we can fix the state if all the other properties are functions of those two properties.  Being &lt;strong&gt;independant&lt;/strong&gt; means that if one property is fixed, the other is still able to be varied. For exmaple, if we fix the x and y axis by telling someone they are not allowed to step forwards,backwards or sideways, the z axis is independant so the person can, in theory, still jump.  Now let us call this a fancy idea the &lt;strong&gt;state postulate&lt;/strong&gt;.  The state postulate dictates how many number of properties is necessary to fix a state.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The state postulate says that the state of a simple compresssible system is completly specific by two independant, intensive properties.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We define a a simple compressible system as on where there isn’t any other external effect acting on it.  This means there isn’t any electrical, magnetic, gravitational, motion or surface tension effects (or those are so small they are assumed to be neglitable since they require external force to make).  Now if we add an signiticant effect on our system, we now need to add an additional property (for every unique type of effect).  For example if we want to consider gravational effect, we must consider z (for height/elevation).  Since temperature and specific volume are always independant, we can always use them to fix the state of a simple compressible system.  If we fix the volume of a system, it can always change temperature.  Same if we fix temperature, we can change the volume.  Why not pressure and temperature? This is because pressures changes with temperature. For example at sea (P = 1 atm) level water boild at 100 degrees C but on a mountain water can boil at a lower temperature.&lt;/p&gt;

&lt;h1 id=&quot;processes-paths-and-cycles&quot;&gt;Processes, Paths and cycles&lt;/h1&gt;

&lt;p&gt;A &lt;strong&gt;process&lt;/strong&gt; is then a system goes from one equilibrium state to another.  The exacty series of states which a system passes through is called the &lt;strong&gt;path.&lt;/strong&gt;&lt;/p&gt;

&lt;h2 id=&quot;understanding-assumptions&quot;&gt;Understanding assumptions&lt;/h2&gt;

&lt;p&gt;Now here is where those assumptions come in.  When someone says a process is isothermal, it means the path which the system takes stays a fixed temperature.  That is the temperature remains constant.  Isobaric means pressure remains constant etc. etc.  The systems follows a path based on the assumption&lt;/p&gt;

&lt;h2 id=&quot;cycle&quot;&gt;Cycle&lt;/h2&gt;

&lt;p&gt;A system goes through a &lt;strong&gt;cycle&lt;/strong&gt; if it returns to its initial state, that is the start and the end states are the same.&lt;/p&gt;

&lt;h2 id=&quot;steady-and-uniform&quot;&gt;Steady and Uniform&lt;/h2&gt;

&lt;p&gt;Steady means no change with time, uniform means no change with location.  You can use these terms in everyday life but if a Waterloo engineering student says he/she has a steady boyfriend/girlfriend they are probably lying.&lt;/p&gt;

&lt;p&gt;A steady-flow process is when a fluid flows through a control volume steadily.  This means they can change with position,  but not with time.  Mass flowing at 1pm should be the same as mass flowing at 3 pm.  This means the energy contents of a control volume stays constant.&lt;/p&gt;

&lt;h1 id=&quot;zeroth-law-of-thermodynamics&quot;&gt;Zeroth law of thermodynamics&lt;/h1&gt;

&lt;p&gt;Now its time for a law: if two bodies are in thermal equilibrium with a third, it means they are thermal equilibrium with each other (even if they are not in contact).  It means temperature measured at one point will be the exact same if the value measured is the same at another.  This is why thermometers work.&lt;/p&gt;

&lt;h1 id=&quot;energy&quot;&gt;Energy&lt;/h1&gt;

&lt;p&gt;We set the total energy (E) to a convenient a reference point (usually 0) since we are usually only interested in the change of energy in our system.  We denote e as energy per unit mass.&lt;/p&gt;

\[e= \frac{E}{m}\]

&lt;h2 id=&quot;internal-energy&quot;&gt;internal energy&lt;/h2&gt;

&lt;p&gt;Internal energy is the sum of all microscopic forms of energy (related to molecular structure and activity), and is denoted using the symbol U&lt;/p&gt;

&lt;h2 id=&quot;kinetic-energy&quot;&gt;kinetic energy&lt;/h2&gt;

\[KE = m \frac {\vee^2}{2}\]

\[ke = \frac{\vee^2}{2}\]

&lt;h2 id=&quot;potential-energy&quot;&gt;Potential energy&lt;/h2&gt;

\[PE = mgz\]

\[pe = gz\]

&lt;h2 id=&quot;mass-and-energy-flow-rate&quot;&gt;mass and energy flow rate&lt;/h2&gt;

&lt;p&gt;Mass is a form of energy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mass flow rate&lt;/strong&gt; amount of mass flowing through a cross section per unit time and can be related to the &lt;em&gt;volume flow rate&lt;/em&gt;:&lt;/p&gt;

\[\dot{m} = \rho \dot{\vee} = \rho A_c V_{avg}\]

&lt;p&gt;where \(\dot{m}\) is mass flow rate, \(\dot{\vee}\) is volume flow rate, and \(A_c\) is cross sectional area of the flow, and \(V_{avg}\) is the average flow velocity (perpendicular to Ac)&lt;/p&gt;

&lt;p&gt;Now we can relate that to energy using:
\(\dot{E} = \dot{m} e\)&lt;/p&gt;

&lt;h2 id=&quot;mechanical-energy-flow-energy&quot;&gt;mechanical energy (flow energy)&lt;/h2&gt;
&lt;p&gt;The mechanical energy of a flowing fluid or flow energy per unit mass is the following:&lt;/p&gt;

\[e_{mech} = \frac{P}{\rho} + \frac{V^2}{2} + gz\]

&lt;p&gt;We can express it in rate form as:&lt;/p&gt;

\[\dot{E}_{mech} = \dot{m} e_{mech} = \dot{m} (\frac{P}{\rho} + \frac{V^2}{2} + gz)\]

&lt;p&gt;If the fluid assumed to be incompressible (density is constant) flow becomes&lt;/p&gt;

\[\Delta e_{mech} = \frac{P_2 - P_1}{\rho} + \frac{V_2^2-V_1^2}{2} + g(z_2-z_1)\]

&lt;p&gt;and&lt;/p&gt;

\[\Delta \dot{E}_{mech} = \dot{m} e_{mech} = \dot{m} (\frac{P_2-P_1}{\rho} + \frac{V_2^2-V_1^2}{2} + g(z_2-z_1)\]

&lt;h1 id=&quot;closed-vs-open-systems&quot;&gt;Closed vs open systems&lt;/h1&gt;

&lt;p&gt;Closed system (or control mass)
fixed mass where no mass crosses system boundary&lt;/p&gt;

&lt;p&gt;Open system (or control volume)
system is an arbitary colume in space&lt;/p&gt;

&lt;h1 id=&quot;heat&quot;&gt;Heat&lt;/h1&gt;

&lt;p&gt;Heat is a form of energy which is transferred between two systems through a temperatuer difference. Heat transfer is denoted by Q, and can be related per unit mass as q.&lt;/p&gt;

\[q = \frac{Q}{m}\]

&lt;p&gt;It crosses the boundary of a closed system.  We assume (for simplicity) that heat always goes into the system.  Since it is a directional quantity, if the heat transfer calculated is negative, then it is going out of the system.&lt;/p&gt;

&lt;h1 id=&quot;work&quot;&gt;Work&lt;/h1&gt;

&lt;p&gt;Work as also cross the boundary of a closed system, and since only heat and work can cross the boundary of a closed system, any form of energy crossing the boundary which is not heat, is work.  Same deal: (for simplicity) work always goes into the system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;work&lt;/strong&gt; form of energy defined as force multiplied by distance.&lt;/p&gt;

\[W =  \int \overrightarrow{F} \dot{}  \overrightarrow{dx} = - \int PAdx = - \int P d\vee\]

&lt;p&gt;Where F is force and x is a displacement vector, P is pressure, A is area.  (note Area multiplied by displacement is a volume)&lt;/p&gt;

&lt;p&gt;SI unit is joules, english system is Btu (British thermal unit)&lt;/p&gt;

&lt;p&gt;Think of a Joule as a newton- meter&lt;/p&gt;

\[1 J = 1 N \times 1 m\]

&lt;p&gt;Btu
energy to raise temperature of 1 lbm (slug) of water at 68 degrees F by 1 degree F.&lt;/p&gt;

&lt;p&gt;1 Btu = 1.0551 kJ.&lt;/p&gt;

&lt;p&gt;1 calorie
amount of energy needed to raise temperature of 1 g of water at 14.5 degress by 1 degree C.&lt;/p&gt;

&lt;p&gt;1 cal = 4.16868 J&lt;/p&gt;

&lt;p&gt;Work per unit mass is denoted by w and is expressed by:&lt;/p&gt;

\[w = \frac{W}{m}\]

&lt;p&gt;Total work is boundary work (see below) plus other work
\(W = W_b + W_{other}\)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Boundary work&lt;/strong&gt; is work done by the expansion and compression of substances.  On a PV diagram it
is the &lt;em&gt;area under the process curve&lt;/em&gt;.  Here are a couple of forms of boundary work:&lt;/p&gt;

&lt;p&gt;General:
\(W_b = - \int_{1}^{2} P dV\)&lt;/p&gt;

\[\delta W_b = F dx = PA dx = P d\vee\]

&lt;p&gt;Where dx is teh change in distance.&lt;/p&gt;

&lt;p&gt;Isobaric (\(P_1 = P_2 = P_0 = constant\)) :&lt;/p&gt;

\[W_b = - P_0 (V_2 - V_1)\]

&lt;p&gt;Polytropic(\(PV^n\)):&lt;/p&gt;

&lt;p&gt;\(W_b = - \frac{P_2 V_2 - P_1 V_1}{1-n}\) , where \(n \ne 1\)&lt;/p&gt;

&lt;p&gt;Isothernal of ideal gas (\(PV = m R T_0 = constant\)):&lt;/p&gt;

\[W_b = P_1 V_1 ln \frac{V_2}{V_1} = mRT_0 ln \frac{V_2}{V_1}\]

&lt;h2 id=&quot;power&quot;&gt;Power&lt;/h2&gt;

&lt;p&gt;power is just work done per unit time and is denoted by:&lt;/p&gt;

\[\dot{W}\]

&lt;h2 id=&quot;important-things-about-work-and-heat-transfer&quot;&gt;Important things about work and heat transfer:&lt;/h2&gt;

&lt;p&gt;Work and heat transfer is actaully path dependant and their magnitudes depend on the path followed during a process.  If you don’t understand this, try and read chapter three of the Cengel textbook, I can’t really explain how I understand this (or if I really do). I would suggest to read the path dependance dependance section for thermodynamic &lt;a href=&quot;https://en.wikipedia.org/wiki/Work_(thermodynamics)&quot;&gt;work&lt;/a&gt;or &lt;a href=&quot;https://en.wikipedia.org/wiki/Nonholonomic_system&quot;&gt;nonholonomic systems&lt;/a&gt; on Wikipedia, but it is pretty complex and poorly explained there :(.&lt;/p&gt;

&lt;p&gt;Ok now so path functions have inexact differentials while point functions (such as properies as volume) have exact differentials.  This means that they depend on the state only and now how a system reached that state.  We use a different symbol for exact and inexact differentals.&lt;/p&gt;

\[\int_{1}^{2} d \vee = \vee_2 - \vee_1 = \Delta V\]

\[\int_{1}^{2}  \delta W = W_{1 \rightarrow 2}\]

&lt;p&gt;Note result of the work integral is not \(\Delta W\) or W2-W1.  This is because work is done by following a process path and is not just measuring a magnitude.&lt;/p&gt;

\[E_2 - E_1 = W_{1 \rightarrow 2} + Q_{1 \rightarrow 2}\]

\[dE = \delta W + \delta Q\]

&lt;p&gt;There equations with determine work of various types (electrical, shaft, spring and many more). You can look them up if you need to use them.&lt;/p&gt;

&lt;h2 id=&quot;first-law-of-thermodynamics&quot;&gt;First law of thermodynamics&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;first law of thermodynamics&lt;/em&gt;: simple expression of conservation of energy (energy is a thermodynamics property)&lt;/p&gt;

&lt;p&gt;Think of it like energy balance:&lt;/p&gt;

&lt;p&gt;Net energy transfer by heat, work and mass = change in all the energies (internal, kinetic, potetial etc.)&lt;/p&gt;

\[E_{in} - E{out} = \Delta E_{system}\]

&lt;p&gt;Now think of it in &lt;em&gt;rate form&lt;/em&gt;:&lt;/p&gt;

\[\dot E_{in} - \dot E{out} = dE_{system}/dt\]

&lt;p&gt;Now think energy is the heat transfer to system (Q) and work done to system (W) is also the same as the sum of the change in internal energy, kinetic energy, potential energy&lt;/p&gt;

\[E = Q + W = \Delta U + \Delta KE + \Delta PE\]

&lt;p&gt;where
\(\Delta U = m(u_2-u_1)\),
\(\Delta KE = \frac{1}{2}m (V_2^2 - V_1^2)\),
\(\Delta PE = mg(z_2-z_1)\),&lt;/p&gt;

&lt;p&gt;Now when there is a &lt;em&gt;constant-pressure process&lt;/em&gt;:&lt;/p&gt;

&lt;p&gt;\(W_b + \Delta U + \delta H\)    &lt;br /&gt;
therefore:&lt;/p&gt;

\[Q -W_{other} = \Delta H + \Delta KE + \Delta PE\]

&lt;h3 id=&quot;mechanisms-of-energy-transfer&quot;&gt;Mechanisms of Energy Transfer&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Heat Transfer Q&lt;/li&gt;
  &lt;li&gt;Work Transfer W&lt;/li&gt;
  &lt;li&gt;Mass flow m (when mass leaves or enters a system it brings or takes energy with it.  Imagine removing hot water from a water heater and replacing it with cold water).&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;energy-conversion-efficiencies&quot;&gt;Energy conversion efficiencies&lt;/h3&gt;

&lt;p&gt;Efficiency describes how well an energy conversion or transfer process is accomplided&lt;/p&gt;

\[Performance = \frac{designed output}{required input}\]

&lt;p&gt;Look up the equation for the specific type of efficiency you are asked when you need it.&lt;/p&gt;

&lt;h1 id=&quot;introducing-enthalpy-and-entropy&quot;&gt;Introducing Enthalpy and Entropy&lt;/h1&gt;

&lt;p&gt;Enthalpy (h) and entropy (s) are also properties of systems.  Don’t worry about entropy until we reach the second law for thermodynamics, just know it exists.&lt;/p&gt;

&lt;p&gt;Enthalpy is a property defined for simplicity and convenience. This means we can use use it often enough to give it a special name and defination:&lt;/p&gt;

\[h = u + P \nu\]

\[H = U + P \vee\]

&lt;p&gt;where U is internal energy and u is internal energy per unit mass.  The book doesn’t explain U or H yet, it just says that they exist and they can be used.&lt;/p&gt;

&lt;p&gt;For example, if you look at table A-4 or A-5 of the Cengel book, you can find $$h_{fg} which is the difference of enthalpy of the saturated liquid and the saturated vapor.  This represents the amount of energy needed to vaporize a unit mass of a saturated liquid at a given temperature or pressure&lt;/p&gt;

&lt;h1 id=&quot;quality&quot;&gt;Quality&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Quality&lt;/strong&gt; x is the ratio of the mass of vapor to the total mass of the mixture:&lt;/p&gt;

\[x = \frac{m_{vapor}}{m_{total}}\]

&lt;p&gt;where\(m_{total} = mass_{liquid} + mass_{vapor} = m_f + m_g\)&lt;/p&gt;

&lt;p&gt;Therefore a saturated liquid has quality = 0 and a saturated vapor has quality = 1.&lt;/p&gt;

&lt;p&gt;If a system consists of a satured mixture (defined at the very top of this page), we can get the average property by using the quality.  Note: properties are independant depending on phase. For example liquid water will have the properties of liquid water, and gaseous water (steam) will have the properties of gasous water even if in the same system.&lt;/p&gt;

\[\nu_{avg} = \nu_f + x \dot{} (\nu_{g} - \nu_{f})\]

&lt;p&gt;we can also rearrange and solve for x&lt;/p&gt;

\[x = \frac{\nu_{avg} - \nu_{f}}{\nu_{g} - \nu_{f}}\]

&lt;p&gt;In the same way we can define this analysis for internal energy (u), enthalpy (h) and enthropy (s) or any general property (y)&lt;/p&gt;

\[u_{avg} = u_f + x \dot{} (u_{g} - u_{f})\]

\[h_{avg} = h_f + x \dot{} (h_{g} - h_{f})\]

\[s_{avg} = s_f + x \dot{} (s_{g} - s_{f})\]

\[y_{avg} = y_f + x \dot{} (y_{g} - y_{f})\]

&lt;p&gt;Note, the average properties of the mixture will always be betwen the values for a saturated liquid and satured vapor:&lt;/p&gt;

\[y_f \leq y_{avg} \leq y_g\]

&lt;h1 id=&quot;ideal-gas&quot;&gt;Ideal Gas&lt;/h1&gt;

&lt;p&gt;Ideal gas equation of state:&lt;/p&gt;

\[P \nu  = RT\]

&lt;p&gt;The other (non specific) form is:&lt;/p&gt;

\[P \vee = mRT\]

&lt;p&gt;where R is the gas constant.  R is different for each gas as is determined by:&lt;/p&gt;

\[R = \frac{R_{universal}}{M}\]

&lt;p&gt;Where Runiversal is the universal gas constant and M is the molar mass.&lt;/p&gt;

&lt;p&gt;Molar mass M is the mass of one mole.  The mass of a system is equal to its molar mass M and the total number of moles N:
\(m = MN\)&lt;/p&gt;

&lt;h1 id=&quot;specific-heats&quot;&gt;Specific Heats&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Specific heat&lt;/strong&gt; is the energy required to raise the temperature of a unit mass of a substance by one degree.&lt;/p&gt;

&lt;p&gt;We are interested in two types of specific heat: constant pressure \(c_p\) and constant volume \(c_{\nu}\).&lt;/p&gt;

&lt;p&gt;\(c_{\nu}\) is the energy required to raise the temperature of a unit mass of a substance by one degree when &lt;em&gt;volume is constant&lt;/em&gt;.  The book says to think of it as the change in internal energy divided by the change in temperature.&lt;/p&gt;

&lt;p&gt;\(C_{\nu} = \frac {\partial u} {\partial T}\)  &lt;br /&gt;
or&lt;br /&gt;
\(u_2 - u_1 = c_{\nu} (T_2-T_1)\) (kJ/kg)&lt;/p&gt;

&lt;p&gt;This is because the change in internal energy for an ideal gas using a process is determined by the following integral:&lt;/p&gt;

&lt;p&gt;\(\Delta u = u_2 - u_1 = \int_{1}^{2}  C_{\nu} (T) dT\) (kJ/kg)&lt;/p&gt;

&lt;p&gt;Cp is energy required to raise the temperature of a unit mass of a substance by one degree when &lt;em&gt;pressure is constant&lt;/em&gt;.  The books says to think of it as the change in enthalpy divided by the change in termperature.&lt;/p&gt;

\[C_{p} = \frac {\partial h} {\partial T}\]

&lt;p&gt;\(h_2 - h_1 = c_{p} (T_2-T_1)\) (kJ/kg)&lt;/p&gt;

&lt;p&gt;This is because the change in enthalpy for an ideal gas using a process is determined by the following integral:&lt;/p&gt;

&lt;p&gt;\(\Delta h = h_2 - h_1 = \int_{1}^{2}  C_{p} (T) dT\) (kJ/kg)&lt;/p&gt;

&lt;p&gt;Specific heat at constant pressure is always greater than at constant volume since at constant pressuer the system is allowed to expand and energy during the expansion creates work into the system.&lt;/p&gt;

&lt;p&gt;We can also relate the gas constant R to specific heat.
\(R = C_p - C_{\nu}\)&lt;/p&gt;

&lt;p&gt;We can also relate Cp and Cv through a property called the &lt;strong&gt;specific heat ratio&lt;/strong&gt; (k)&lt;/p&gt;

\[k = \frac{c_p}{c_{\nu}}\]

&lt;p&gt;I will explain this better below (after real gas and boundary work).&lt;/p&gt;

&lt;h2 id=&quot;real-gas&quot;&gt;Real Gas:&lt;/h2&gt;

&lt;p&gt;Near the saturated region and critial point, gasses can behave unideally, so we use Z to denote a compressibility factor:&lt;/p&gt;

\[P \nu = ZRT\]

&lt;p&gt;More on this soon to come!&lt;/p&gt;

\[\frac{dE}{dt}=  \dot{W} +\dot{Q}+ \dot{M_{in}} (e+pv)_{in} - \dot{M_{out}} (e+pv)_{out}\]

&lt;h1 id=&quot;u-s-h-of-solids-and-liquids&quot;&gt;U, S, H of Solids and Liquids&lt;/h1&gt;

&lt;p&gt;We usually assume that solids and liquids have a constant specific volume, and we called this an incompressible substance.  In this case, the specifics will be the same and just noted as c
\(c_{\nu} = c_p = c\)&lt;/p&gt;

&lt;p&gt;Now we can do some derivations and show that if we know c value at an average temperature, we can determine the approximate internal energy. That is:&lt;/p&gt;

\[\Delta u \cong c_{avg} (T_2 - T_1)\]

&lt;p&gt;\(\Delta h = \Delta u + \nu \Delta P \cong c_{avg} \Delta T + \nu \Delta P\) (kJ/kg)&lt;/p&gt;

&lt;p&gt;We can also show that since solids are incompressible, the liquid properties remain that same at difference temperature.&lt;/p&gt;

\[du = dh = C_v dT = C_p dT = \bar c dT\]

&lt;p&gt;That is:
\(\Big\{u, v, h, s \Big\}_{liq} \cong \Big\{u(T), v(T), h(T), s(T) \Big\}_{T}\)&lt;/p&gt;

</description>
                <link>https://mrandrewandrade.github.io/blog/2015/10/25/thermodynamics-101-reference.html</link>
                <guid>https://mrandrewandrade.github.io/blog/2015/10/25/thermodynamics-101-reference</guid>
                <pubDate>Sun, 25 Oct 2015 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>How measure temperature using a thermistor and BeagleBone Black</title>
                <description>&lt;h1 id=&quot;results-from-modeling-a-thermister&quot;&gt;Results from Modeling a Thermister&lt;/h1&gt;

&lt;p&gt;In the &lt;a href=&quot;https://andrewandrade.ca/blog/2015/10/22/modeling-thermistor-using-data-science.html&quot;&gt;last blog post&lt;/a&gt;, I described a long winded approach about how I built a model for a thermister to relate the voltage measured from a BeagleBoneBlack (BBB) microcontroller to the temperature.  This post will summarize the results from the model, and explain how to connect up the system.&lt;/p&gt;

&lt;h2 id=&quot;thermal-sensor-data&quot;&gt;Thermal Sensor Data&lt;/h2&gt;

&lt;p&gt;The thermal sensor used is a 100k thermistor &lt;a href=&quot;http://www.robotdigg.com/product/198/3950+100k+thermistor+with+1m+cables&quot;&gt;Part No. HT100K3950-1&lt;/a&gt; invidually connected to a 1m cable:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hotend Thermistor&lt;/strong&gt; &lt;br /&gt;
100K Glass-sealed Thermistor
3950 1% thermistor 1.8mm glass head    &lt;br /&gt;
1M long cables 2 wires  &lt;br /&gt;
PTFE Tube 0.6*1mm to protect from the thermistor   &lt;br /&gt;
Shrink wrap between thermistor and the cables.&lt;/p&gt;

&lt;p&gt;The site included a weird &lt;a href=&quot;http://www.robotdigg.com/upload/pdf/100k-thermistor.doc&quot;&gt;word document&lt;/a&gt; with a bunch of numbers.  I saved the data as a &lt;a href=&quot;https://andrewandrade.ca/datasets/100k-thermistor.csv&quot;&gt;.csv&lt;/a&gt; file so I can use the data in python.  If you want to follow along, you can you download the document &lt;a href=&quot;https://andrewandrade.ca/datasets/100k-thermistor.csv&quot;&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I then made a chart which includes the expected resistance and the errors.  This chart summarizes the data provided by the manufacturer:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;c1&quot;&gt;#import necessary libraries:
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pandas&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pd&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pylab&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;P&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;plotly.plotly&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;py&lt;/span&gt;

&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;math&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;scipy.optimize&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;curve_fit&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;matplotlib.mlab&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mlab&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;matplotlib.gridspec&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;gridspec&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;#comment below if not using ipython/jupyter notebook
&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;matplotlib&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inline&lt;/span&gt; 

&lt;span class=&quot;c1&quot;&gt;#read csv and label columns
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read_csv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;100k-thermistor.csv&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;columns&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;temperature&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;r_max&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;r_norm&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;r_min&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;lower_error&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_norm&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_min&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;upper_error&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_max&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_norm&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;asymmetric_error&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lower_error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;upper_error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;fig1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;figure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;k&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;expected resistance&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;Expected Resistance vs Temperature&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Temperature (degrees C)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Resistance (kohm)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;#plt.show()
#py.iplot_mpl(fig1)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;iframe frameborder=&quot;0&quot; seamless=&quot;seamless&quot; scrolling=&quot;no&quot; src=&quot;https://plot.ly/~mrandrewandrade/84.embed&quot; height=&quot;525px&quot; width=&quot;100%&quot;&gt;&lt;/iframe&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;n&quot;&gt;fig2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;figure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_min&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;lower error&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_max&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;upper error&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Upper and Lower Error vs Temperature&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Temperature (Celcius)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Resistance (kohm)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;#py.iplot_mpl(fig2)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;iframe frameborder=&quot;0&quot; seamless=&quot;seamless&quot; scrolling=&quot;no&quot; src=&quot;https://plot.ly/~mrandrewandrade/80.embed&quot; height=&quot;525px&quot; width=&quot;100%&quot;&gt;&lt;/iframe&gt;

&lt;p&gt;We than then limit the data to operating temperature range which I care about:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;c1&quot;&gt;#set the desired upper and lower temperature
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lower_temp_range&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;19&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;upper_temp_range&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;81&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;#starting_temp sets the index adjustement for array
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;starting_temp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;selected_temp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lower_temp_range&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;starting_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;upper_temp_range&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;starting_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;selected_r_norm&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lower_temp_range&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;starting_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;upper_temp_range&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;starting_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;fig1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;figure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;selected_r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;k&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;expected resistance&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;Expected Resistance vs Temperature&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Temperature (degrees C)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Resistance (kohm)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;#plt.show()
&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;#this makes an interative plot using plotly
#py.iplot_mpl(fig1)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;iframe frameborder=&quot;0&quot; seamless=&quot;seamless&quot; scrolling=&quot;no&quot; src=&quot;https://plot.ly/~mrandrewandrade/95.embed&quot; height=&quot;525px&quot; width=&quot;100%&quot;&gt;&lt;/iframe&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;n&quot;&gt;selected_r_min&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_min&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lower_temp_range&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;starting_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;upper_temp_range&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;starting_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;selected_r_max&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lower_temp_range&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;starting_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;upper_temp_range&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;starting_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;


&lt;span class=&quot;n&quot;&gt;fig2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;figure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_r_min&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;lower error&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_r_max&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;upper error&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Upper and Lower Error vs Temperature&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Temperature (Celcius)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Resistance (kohm)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;#comment if not using plotly
#py.iplot_mpl(fig2)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;iframe frameborder=&quot;0&quot; seamless=&quot;seamless&quot; scrolling=&quot;no&quot; src=&quot;https://plot.ly/~mrandrewandrade/97.embed&quot; height=&quot;525px&quot; width=&quot;100%&quot;&gt;&lt;/iframe&gt;

&lt;p&gt;Based on the Resistance vs Temperature Chart, we can make an assumption that the distribution follows the relationship followed by this fitness function:&lt;/p&gt;

&lt;p&gt;\(resistance = a e^{-b \times temperature} + c\)
where resistance is meaured in \(k\Omega\), temperature measued in degrees celcius, and the constants a, b, and c can be found (through curve fitting).&lt;/p&gt;

&lt;p&gt;Lets define the fitness function and find the constants a, b, and c.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;fitness_function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# kohm
&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;selected_temp_fit_parms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;selected_temp_fit_covariances&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;curve_fit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fitness_function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                                    &lt;span class=&quot;n&quot;&gt;selected_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;selected_r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos; fit coefficients:&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;selected_temp_fit_parms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;a=&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_temp_fit_parms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;b=&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_temp_fit_parms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;c=&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_temp_fit_parms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos; Covariance matrix:&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;selected_temp_fit_covariances&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;selected_temp_fit&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fitness_function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                 &lt;span class=&quot;n&quot;&gt;selected_temp_fit_parms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
                                 &lt;span class=&quot;n&quot;&gt;selected_temp_fit_parms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
                                 &lt;span class=&quot;n&quot;&gt;selected_temp_fit_parms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;residual_error_selected&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;selected_temp_fit&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_r_norm&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;fig3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;figure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;selected_temp_fit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;curve fit&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;color&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;k&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Temperature (Celcius)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Resistance (kohm)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Curve Fit Resitance vs Temperature&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;#py.iplot_mpl(fig3)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; fit coefficients:
[  2.95517151e+02   4.52495454e-02   5.12190680e+00] 

a= 295.517150959 

b= 0.0452495454444 

c= 5.12190680215 

 Covariance matrix:
[[  6.94401115e-01   1.20117237e-04   8.77447476e-02]
 [  1.20117237e-04   2.41377772e-08   2.04485474e-05]
 [  8.77447476e-02   2.04485474e-05   2.05394937e-02]]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;iframe frameborder=&quot;0&quot; seamless=&quot;seamless&quot; scrolling=&quot;no&quot; src=&quot;https://plot.ly/~mrandrewandrade/105.embed&quot; height=&quot;525px&quot; width=&quot;100%&quot;&gt;&lt;/iframe&gt;

&lt;p&gt;Now lets plot the expected resistance, curve fit resistance and residuals to understand the error in the curve fit:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;figure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;selected_temp_fit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;curve fit&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;selected_r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;expected&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;residual_error_selected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;r&apos;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;residual error&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;legend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bbox_to_anchor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.02&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;102&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;loc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
           &lt;span class=&quot;n&quot;&gt;ncol&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;expand&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;borderaxespad&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Temperature (Celcius)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Resistance (kohm)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;figure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;residual_error_selected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;r&apos;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;residual error&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Temperature (Celcius)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Residual Error in Curve Fit (kohm)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Residual Error in Curve Fit Across Full Temperature Range&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;figure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# convert numpy series to array
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;residual_error_list&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;residual_error_selected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tolist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;residual_error_array&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;asarray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;residual_error_list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;error_mean&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mean&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;residual_error_array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;error_sigma&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;residual_error_array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Residual mean (Kohm):&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error_mean&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Residual std dev (Kohm):&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error_sigma&lt;/span&gt;


&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bins&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;patches&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;residual_error_array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;normed&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;facecolor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;red&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.75&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Error in Curve fit (kohm)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Residual Distribution&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;P&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;normpdf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bins&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error_mean&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error_sigma&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;l&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;P&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bins&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;k--&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;linewidth&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Residual mean (Kohm):
-8.15077359012e-09
Residual std dev (Kohm):
0.264370345418
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;https://andrewandrade.ca/blog/images/modeling-thermistor-using-data-science/output_23_1.png&quot; alt=&quot;png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://andrewandrade.ca/blog/images/modeling-thermistor-using-data-science/output_23_2.png&quot; alt=&quot;png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://andrewandrade.ca/blog/images/modeling-thermistor-using-data-science/output_23_3.png&quot; alt=&quot;png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;As we can see, the residual error is very small compared to the range of resistance, and follows a (some what) normal distribution.  That we have a model of resistance vs temperature, lets set up our microcontroller (BBB) to measure temperature.  Since our sensor is a variable resistor, we can take an analog mesaurement by passing a current though the thermister and measuring the voltage accross it. Since we need to limit our input voltage to 1.8 V (according to the BBB spec, we can use a voltage divider to limit the maximum voltage accross the thermistor (as shown below)&lt;/p&gt;

&lt;iframe title=&quot;measuring-temperature-thermistor&quot; width=&quot;100%&quot; height=&quot;600px&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; name=&quot;measuring-temperature-thermistor&quot; class=&quot;eda_tool&quot; src=&quot;https://upverter.com/eda/embed/#designId=c31c38d140bec875,actionId=&quot;&gt;&lt;/iframe&gt;

&lt;p&gt;In our case, we need to calculate the correct R1 to ensure the voltage accross the thermistor (which is read through the analog input pin of the BBB) does not exceed 1.8V based on the maximum operating range of temperature.  For us this is between 0C and 100 C.  Based on the plot of the resistance vs temperature for the thermistor, we know that at 0C, the resistance of the thermistor is a maximum of 327.240 Kohm. We can then use this value as R2 in a generic voltage divider, to calculate for R1.&lt;/p&gt;

&lt;iframe title=&quot;voltage-divider&quot; width=&quot;100%&quot; height=&quot;600px&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; name=&quot;voltage-divider&quot; class=&quot;eda_tool&quot; src=&quot;https://upverter.com/eda/embed/#designId=79ccecb425cbbda4,actionId=&quot;&gt;&lt;/iframe&gt;

\[R_1 = R_2 \frac{V_{in}}{V_o} - R_2\]

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;n&quot;&gt;v_in&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;3.3&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#V
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v_out&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.8&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#V
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_2_max&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;327260&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#ohm
&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;r_1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r_2_max&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v_in&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v_out&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r_2_max&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#ohm
&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Minimum value for R1 in kohms&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r_1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#kohm&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Minimum value for R1 in kohms
272.716666667
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Looking at the standard 1% &lt;a href=&quot;http://www.brannonelectronics.com/images/STANDARD%20VALUE.pdf&quot;&gt;resistor chart&lt;/a&gt; or &lt;a href=&quot;http://www.daycounter.com/Calculators/Standard-Resistor-Value-Calculator.phtml&quot;&gt;calculator&lt;/a&gt; we now know we should use 274k ohm resistor for R1.&lt;/p&gt;

&lt;p&gt;Now that we have R1 and Vin set as constants and we can measure Vo from the BBB’s analog input pin, we can now write a rearrange the voltage divider equation and fitness function to relate Vo to temperature.  The previous blog post goes over this, but the resulting function is here:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;voltage_to_temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;voltage_reading&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;#calculated to limit input voltage 1.8V max
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;v_in&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;3.3&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#Volts
&lt;/span&gt;    
    &lt;span class=&quot;n&quot;&gt;r_1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;274&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#kohm
&lt;/span&gt;    
    &lt;span class=&quot;c1&quot;&gt;#taken by curve fitting
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;2.94311453&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;pow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;4.51009053&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;pow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;5.054388390&lt;/span&gt;
    
    &lt;span class=&quot;c1&quot;&gt;#taken from voltage divider equation
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;r_2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r_1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;voltage_reading&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v_in&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;voltage_reading&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# kohm
&lt;/span&gt;    
    &lt;span class=&quot;c1&quot;&gt;#taken from rearraging fitness function
&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;#solve r_2 = a*np.exp(-b*temperature) + c) for t
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#degrees C
&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;We can now use this function and plot for the full range of input voltages:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;n&quot;&gt;v_measured_min&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#V
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v_measured_max&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.8&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#V
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v_sweep&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linspace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v_measured_min&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;v_measured_max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;num&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;temperature_profile&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;voltage_to_temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v_sweep&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;fig&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;figure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v_sweep&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature_profile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Temperature (Celcius)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Measured Voltage (V)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Temperature vs Measured Voltage&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;#py.iplot_mpl(fig)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;iframe frameborder=&quot;0&quot; seamless=&quot;seamless&quot; scrolling=&quot;no&quot; src=&quot;https://plot.ly/~mrandrewandrade/107.embed&quot; height=&quot;525px&quot; width=&quot;100%&quot;&gt;&lt;/iframe&gt;

</description>
                <link>https://mrandrewandrade.github.io/blog/2015/10/23/measure-temperature-thermistor-beaglebone.html</link>
                <guid>https://mrandrewandrade.github.io/blog/2015/10/23/measure-temperature-thermistor-beaglebone</guid>
                <pubDate>Fri, 23 Oct 2015 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>Modeling a Thermister: Merging Hardware Engineering and Data Science</title>
                <description>&lt;p&gt;In the &lt;a href=&quot;https://andrewandrade.ca/blog/2015/10/21/battery-testing.html&quot;&gt;last blog post&lt;/a&gt;, I talked about voltage dividers and how they can be used to limit voltage to eventually connect to an ADC to measure voltage on a BeagleBone.  Today I am going to build on the voltage divider and pair hardware engineering with data science.  The next couple of posts will be pieces of battery testing rig, and then I will put it all togeather to explain how the full system works. First things first, what temperature sensor should we use?&lt;/p&gt;

&lt;h2 id=&quot;selecting-a-thermal-sensor&quot;&gt;Selecting a Thermal Sensor&lt;/h2&gt;

&lt;p&gt;Half due to avaliability, and the other half due to shear laziness (of not wanting to buy sensors), I decided we are going to use thermisters as our temperature sensor of choice.  A friend hand a bunch so why use them?&lt;/p&gt;

&lt;p&gt;Specifically, he gave me a bunch of 100k thermistors &lt;a href=&quot;http://www.robotdigg.com/product/198/3950+100k+thermistor+with+1m+cables&quot;&gt;Part No. HT100K3950-1&lt;/a&gt; invidually connected to a 1m cable.&lt;/p&gt;

&lt;h2 id=&quot;what-is-a-thermister&quot;&gt;What is a thermister?&lt;/h2&gt;

&lt;p&gt;A thermister can be simply defined as a special type of resistor whose resistance is highly dependent on temperature.  Therefore if you are able to measure the resistance on the thermister, you can easily determine the temperature if you know how the thermister behaves.  Simple enough right?&lt;/p&gt;

&lt;p&gt;If you go to the &lt;a href=&quot;http://www.robotdigg.com/product/198/3950+100k+thermistor+with+1m+cables&quot;&gt;site&lt;/a&gt; which sells them, they give a bit more information:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hotend Thermistor&lt;/strong&gt;
100K Glass-sealed Thermistor
3950 1% thermistor 1.8mm glass head  &lt;br /&gt;
1M long cables 2 wires  &lt;br /&gt;
PTFE Tube 0.6*1mm to protect from the thermistor  &lt;br /&gt;
Shrink wrap between thermistor and the cables.&lt;/p&gt;

&lt;p&gt;The most important piece of information to get started using the thermister is its behaviour responding to temperature.  Luckly for me, my friend sent me the data which was on the site.  When you have a table or chart which maps the resistance to temperature, you can simply measure the resistance with a multimemter and look up the temperature on the chart, or you can again use a voltage divider and connect it to an ADC (more on that later).&lt;/p&gt;

&lt;h2 id=&quot;mapping-resistance-to-temperature-using-curve-fitting&quot;&gt;Mapping Resistance to Temperature using Curve Fitting&lt;/h2&gt;
&lt;p&gt;The site included a weird &lt;a href=&quot;http://www.robotdigg.com/upload/pdf/100k-thermistor.doc&quot;&gt;word document&lt;/a&gt; with a bunch of numbers.  It really confuses me why one would have tabular data in a word document, a spreadsheet serves that purpose.  Anyways, the information was easily extractable and I was able to put it into an spreadsheet and save as a .CSV file.  If you want to follow along, you can you download the document &lt;a href=&quot;https://andrewandrade.ca/datasets/100k-thermistor.csv&quot;&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you own the file in a speadsheet program or in your text editor of choice, you can see there are four columns: temperature in Celcius, maximum resistance in \(k\Omega\),  normal (average)resistance in \(k\Omega\) and  minimum resistance in \(k\Omega\) .  If we were measuring the resistance by hand, we could simply just look up (and eyeball) the closest resistance value and read of the temperature.  We could be more fancy and use &lt;a href=&quot;https://en.wikipedia.org/wiki/Linear_interpolation&quot;&gt;linear interpolation&lt;/a&gt; as an alternative to eyeballing.&lt;/p&gt;

&lt;p&gt;That is all great, but our goal is to use a micocontroller (or computer) to store, measure and use the temperature readings.  This means we have to mathematically model how the thermister behaves. Since we have data provided from the manufacturer, we do this by plotting the data which was provided:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;c1&quot;&gt;#import necessary libraries:
&lt;/span&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pandas&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pd&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;numpy&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;pylab&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;P&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;math&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;scipy.optimize&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;curve_fit&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;matplotlib.pyplot&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;matplotlib.mlab&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mlab&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;matplotlib.gridspec&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;gridspec&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;#comment below if not using ipython/jupyter notebook
&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;matplotlib&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inline&lt;/span&gt; 

&lt;span class=&quot;c1&quot;&gt;#read csv and label columns
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pd&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;read_csv&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;100k-thermistor.csv&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;columns&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;temperature&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;r_max&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;r_norm&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;r_min&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;#plot temperature as x, r_norm as y over full range of temperature
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;average resistance&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;#label axis
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Temperature (Celcius)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Resistance (kohm)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Expected Resistance vs Temperature of 100K Thermistor&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;&lt;img src=&quot;https://andrewandrade.ca/blog/images/modeling-thermistor-using-data-science/output_1_1.png&quot; alt=&quot;png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Now we can see that it does not have a linear relation.  Actually it has a inverse relation or an \(x^{n}\) where $n&amp;lt;0$ most probably.  Since I am curious, I plotted the min and the max resistance to get a better feel for the error in the temperature reading. My ituition tells me that that is th range the thermister operates in.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;expected resistance&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_min&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;min resistance&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;max resistance&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;legend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bbox_to_anchor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.02&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;102&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;loc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
           &lt;span class=&quot;n&quot;&gt;ncol&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;expand&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;borderaxespad&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Temperature (Celcius)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Resistance (kohm)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Resistance vs Temperature of 100K Thermistor&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;&lt;img src=&quot;https://andrewandrade.ca/blog/images/modeling-thermistor-using-data-science/output_3_1.png&quot; alt=&quot;png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Now, the top graph, isn’t that useful.  All it shows is that the range is very small, and is wider (there is more error) when temperatures are below 0 degrees.  To see if we can do better, lets limit the range (with contingency) of the temperatures we will be dealing with on the project: 0-100 degrees.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;expected resistance&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_min&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;min resistance&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;max resistance&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Temperature (Celcius)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Resistance (kohm)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;legend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bbox_to_anchor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.02&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;102&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;loc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
           &lt;span class=&quot;n&quot;&gt;ncol&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;expand&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;borderaxespad&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;&lt;img src=&quot;https://andrewandrade.ca/blog/images/modeling-thermistor-using-data-science/output_5_1.png&quot; alt=&quot;png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The plot is a bit clearer but not perfect, let’s try and be more fancy and reprensent the error with error bars like they do in stats 101.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;lower_error&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_norm&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_min&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;upper_error&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_max&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_norm&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;asymmetric_error&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lower_error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;upper_error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;errorbar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;yerr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;asymmetric_error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ecolor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;r&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Resistance vs Temperature of 100K Thermistor&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Temperature (Celcius)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Resistance (kohm)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;#plt.show()&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;&lt;img src=&quot;https://andrewandrade.ca/blog/images/modeling-thermistor-using-data-science/output_7_1.png&quot; alt=&quot;png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Great!  A bit better, but it is still hard to read.  Let’s try plotting the error on the same axis as the expected (normal) resistance.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_min&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;lower error&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;upper error&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;expected resistance&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Temperature (Celcius)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Resistance (kohm)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;legend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bbox_to_anchor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.02&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;102&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;loc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
           &lt;span class=&quot;n&quot;&gt;ncol&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;expand&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;borderaxespad&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;&lt;img src=&quot;https://andrewandrade.ca/blog/images/modeling-thermistor-using-data-science/output_9_1.png&quot; alt=&quot;png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;From this figure it is quite clear as tempertature decreases, there is more error in the thermistor reading.  This figure also shows that reading taken over 20 C should have good accuracy.  We can even take this futher by one more plot&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_min&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;lower error&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;upper error&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Temperature (Celcius)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Resistance (kohm)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;legend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bbox_to_anchor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.02&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;102&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;loc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
           &lt;span class=&quot;n&quot;&gt;ncol&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;expand&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;borderaxespad&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;&lt;img src=&quot;https://andrewandrade.ca/blog/images/modeling-thermistor-using-data-science/output_12_1.png&quot; alt=&quot;png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This figure shows the upper and lower bound of error (to be around \(\pm 1.5k\Omega\))+ 125 kohm, since the expected reading would be around \(125kOmega\) at 20 degrees C.  Knowing the smallest resistance within our operating range will occur at 100 degrees (around \(6720\Omega\)), R_1 can be calculated to be around \(1200\Omega\) using the voltage divider presented in the previous post.  Now, the largest possible error can be calculated and used as a very conservative estime of the temperature reading resolution.  Before we do that, let us fit a curve to the data.  Using grade 11 math, we can estimate that the function which discribes the invest curve would look something like \(resistance = a \times e^{-b \times temprature} + c\).  We can then use SciPy’s &lt;a href=&quot;http://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.optimize.curve_fit.html&quot;&gt;curve_fit&lt;/a&gt; to determine the fit parameters and the covarience matrix.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;fitness_function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;exp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;full_temp_fit_parms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;full_temp_fit_covariances&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;curve_fit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fitness_function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                                           &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos; full temperature fit coefficients:&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;full_temp_fit_parms&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos; Covariance matrix:&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;full_temp_fit_covariances&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; full temperature fit coefficients:
[  3.22248984e+02   5.51886907e-02   4.56056442e+00]
 Covariance matrix:
[[  1.82147996e+00  -2.16345654e-04  -2.82466975e-01]
 [ -2.16345654e-04   2.97792772e-08   2.87522862e-05]
 [ -2.82466975e-01   2.87522862e-05   2.25733939e-01]]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The fit coefficients are now known!  This means that the following equation approximates the behaviour of the thermister: 
\(resistance = 322 \times e^{-0.055 \times temprature} + 4.56\)&lt;/p&gt;

&lt;p&gt;We can also determine the standard deviation of the fit from the diagonal of the covariance matrix, and plot it for each parameter.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;c1&quot;&gt;# standard deviation of each paramter
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sigma&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;math&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sqrt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;full_temp_fit_covariances&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]),&lt;/span&gt; 
         &lt;span class=&quot;n&quot;&gt;math&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sqrt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;full_temp_fit_covariances&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]),&lt;/span&gt; 
         &lt;span class=&quot;n&quot;&gt;math&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sqrt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;full_temp_fit_covariances&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;x0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linspace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;300&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;340&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linspace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.05&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.06&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;x2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linspace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;fig&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;figure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mlab&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;normpdf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;full_temp_fit_parms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sigma&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Uncertainty in fit parameter a&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Parameter a&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Standard Deviation&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;fig&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;figure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mlab&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;normpdf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;full_temp_fit_parms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sigma&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;uncertainty in fit parameter b&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;fig&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;figure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mlab&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;normpdf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;full_temp_fit_parms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sigma&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;uncertainty in fit parameter c&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;#plt.show()&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;&lt;img src=&quot;https://andrewandrade.ca/blog/images/modeling-thermistor-using-data-science/output_16_1.png&quot; alt=&quot;png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://andrewandrade.ca/blog/images/modeling-thermistor-using-data-science/output_16_2.png&quot; alt=&quot;png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://andrewandrade.ca/blog/images/modeling-thermistor-using-data-science/output_16_3.png&quot; alt=&quot;png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;As we can see, the standard deviation is very small and thus results in a good fit accross the full range of temperature as shown in the three figures below:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;n&quot;&gt;full_temp_fit&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fitness_function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                 &lt;span class=&quot;n&quot;&gt;full_temp_fit_parms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
                                 &lt;span class=&quot;n&quot;&gt;full_temp_fit_parms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
                                 &lt;span class=&quot;n&quot;&gt;full_temp_fit_parms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;residual_error&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;full_temp_fit&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_norm&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;figure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;full_temp_fit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;curve fit&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;expected&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;residual_error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;residual error&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;legend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bbox_to_anchor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.02&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;102&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;loc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
           &lt;span class=&quot;n&quot;&gt;ncol&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;expand&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;borderaxespad&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Temperature (Celcius)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Resistance (kohm)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Resistance vs Temperature of 100K Thermistor&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;figure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;residual_error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;r&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;residual error&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Temperature (Celcius)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Residual Error in Curve Fit (kohm)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Residual Error in Curve Fit Across Full Temperature Range&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;figure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bins&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;patches&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;residual_error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;normed&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;facecolor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;red&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.75&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Error in Curve fit (kohm)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Residual Distribution&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;&lt;img src=&quot;https://andrewandrade.ca/blog/images/modeling-thermistor-using-data-science/output_18_1.png&quot; alt=&quot;png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://andrewandrade.ca/blog/images/modeling-thermistor-using-data-science/output_18_2.png&quot; alt=&quot;png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://andrewandrade.ca/blog/images/modeling-thermistor-using-data-science/output_18_3.png&quot; alt=&quot;png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;While the model accross the full temperature is useful, we can improve our model by curve fitting only in the temperature range we are interested in.  This prevents the algorithm for compesating for select set of data which is irrevant.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;c1&quot;&gt;#temperature ranger 0 to 100 degrees
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_temp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;selected_r_norm&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;130&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;selected_temp_fit_parms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;selected_temp_fit_covariances&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;curve_fit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fitness_function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                                    &lt;span class=&quot;n&quot;&gt;selected_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;selected_r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos; fit coefficients:&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;selected_temp_fit_parms&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos; Covariance matrix:&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;selected_temp_fit_covariances&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;selected_temp_fit&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fitness_function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                 &lt;span class=&quot;n&quot;&gt;selected_temp_fit_parms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
                                 &lt;span class=&quot;n&quot;&gt;selected_temp_fit_parms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
                                 &lt;span class=&quot;n&quot;&gt;selected_temp_fit_parms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;residual_error_selected&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;selected_temp_fit&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_r_norm&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;figure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;selected_temp_fit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;curve fit&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;selected_r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;expected&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;residual_error_selected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;r&apos;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;residual error&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;legend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bbox_to_anchor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.02&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;102&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;loc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
           &lt;span class=&quot;n&quot;&gt;ncol&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;expand&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;borderaxespad&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Temperature (Celcius)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Resistance (kohm)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;figure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;residual_error_selected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;r&apos;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;residual error&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Temperature (Celcius)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Residual Error in Curve Fit (kohm)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Residual Error in Curve Fit Across Full Temperature Range&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;figure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# convert numpy series to array
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;residual_error_list&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;residual_error_selected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tolist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;residual_error_array&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;asarray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;residual_error_list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bins&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;patches&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;residual_error_array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;normed&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;facecolor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;red&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.75&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Error in Curve fit (kohm)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Residual Distribution&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; fit coefficients:
[  3.16643400e+02   4.84933743e-02   6.53548105e+00]
 Covariance matrix:
[[  3.29405526e-01   4.07305280e-05  -1.67742297e-02]
 [  4.07305280e-05   3.89687128e-08   4.14707796e-05]
 [ -1.67742297e-02   4.14707796e-05   7.51633680e-02]]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;https://andrewandrade.ca/blog/images/modeling-thermistor-using-data-science/output_20_2.png&quot; alt=&quot;png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://andrewandrade.ca/blog/images/modeling-thermistor-using-data-science/output_20_3.png&quot; alt=&quot;png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://andrewandrade.ca/blog/images/modeling-thermistor-using-data-science/output_20_4.png&quot; alt=&quot;png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;We can see the difference by comparing both of the curve fit models on the interested temperature range:&lt;/p&gt;

&lt;p&gt;While the testing spec we developed states we should have the capability of measuring from 0-100 degress C, the average range of operation is actually between 20-80 degrees C, so we can change the range to match the standard operating range&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;c1&quot;&gt;#temperature ranger 0 to 100 degrees
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_temp&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;110&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;selected_r_norm&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;110&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;selected_temp_fit_parms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;selected_temp_fit_covariances&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;curve_fit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fitness_function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                                    &lt;span class=&quot;n&quot;&gt;selected_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;selected_r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos; fit coefficients:&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;selected_temp_fit_parms&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos; Covariance matrix:&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;selected_temp_fit_covariances&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;selected_temp_fit&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fitness_function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                 &lt;span class=&quot;n&quot;&gt;selected_temp_fit_parms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
                                 &lt;span class=&quot;n&quot;&gt;selected_temp_fit_parms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
                                 &lt;span class=&quot;n&quot;&gt;selected_temp_fit_parms&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;residual_error_selected&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;selected_temp_fit&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_r_norm&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;figure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;selected_temp_fit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;curve fit&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;selected_r_norm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;expected&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;residual_error_selected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;r&apos;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;residual error&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;legend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bbox_to_anchor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.02&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;102&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;loc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
           &lt;span class=&quot;n&quot;&gt;ncol&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mode&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;expand&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;borderaxespad&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Temperature (Celcius)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Resistance (kohm)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;figure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selected_temp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;residual_error_selected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;r&apos;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;residual error&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Temperature (Celcius)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Residual Error in Curve Fit (kohm)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Residual Error in Curve Fit Across Full Temperature Range&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;figure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;# convert numpy series to array
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;residual_error_list&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;residual_error_selected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tolist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;residual_error_array&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;asarray&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;residual_error_list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;error_mean&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mean&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;residual_error_array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;error_sigma&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;residual_error_array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Residual mean (Kohm):&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error_mean&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Residual std dev (Kohm):&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error_sigma&lt;/span&gt;


&lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bins&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;patches&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;residual_error_array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;normed&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;facecolor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;red&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alpha&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.75&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Error in Curve fit (kohm)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Residual Distribution&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;P&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;normpdf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bins&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error_mean&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error_sigma&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;l&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;P&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bins&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&apos;k--&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;linewidth&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; fit coefficients:
[  2.94311453e+02   4.51009053e-02   5.05438839e+00]
 Covariance matrix:
[[  6.57786227e-01   1.12143572e-04   8.24269669e-02]
 [  1.12143572e-04   2.18837795e-08   1.84056321e-05]
 [  8.24269669e-02   1.84056321e-05   1.81122519e-02]]
Residual mean (Kohm):
9.99334067349e-10
Residual std dev (Kohm):
0.2302444024
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;https://andrewandrade.ca/blog/images/modeling-thermistor-using-data-science/output_23_1.png&quot; alt=&quot;png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://andrewandrade.ca/blog/images/modeling-thermistor-using-data-science/output_23_2.png&quot; alt=&quot;png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://andrewandrade.ca/blog/images/modeling-thermistor-using-data-science/output_23_3.png&quot; alt=&quot;png&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The results of the curve fit within the standard operating temperature is much better.  Now only is residual error mean essentually zero (9.99e-10 k ohm) with a relatively small standard deviation (0.230 kohm), but the residual error have the general appearance of being normally distributed (unlike the previous curve fits).  What this means is that, the model will predict the resistance very well (have a very low error) for the stardard operating temperatures, but will perform poorer outside.  Luckly for us, our battries will not be operating below 20 degrees C or above 80 degrees C.&lt;/p&gt;

&lt;h3 id=&quot;curve-fit-model&quot;&gt;Curve fit model:&lt;/h3&gt;

&lt;p&gt;The model we created can now be sumarized to the following equation:&lt;/p&gt;

&lt;p&gt;\(R_2 = a e^{-b \times temperature} + c\)
where R_2 is meaured in \(k\Omega\), temperature measued in degree celcius, and the constants a, b, and c were found (through curve fitting) to be:&lt;/p&gt;

&lt;p&gt;\(a = 2.94311453 \times 10^2\)    &lt;br /&gt;
\(b = 4.51009053 \times 10 ^{-02}\)    &lt;br /&gt;
\(c = 5.054388390\)&lt;/p&gt;

&lt;p&gt;In addition, the error in the curve fitting is averaged at 9.99334067349e-10 kohm and the standard deviation of 0.2302444024 kohm.  This error, while small can later be used in filtering algorithms when we are monitoring the temperature.  I will touch on this in a later post, but this data about statistical noise while reading can aid in estimating temperature through more advance software (such as using &lt;a href=&quot;https://www.google.ca/url?sa=t&amp;amp;rct=j&amp;amp;q=&amp;amp;esrc=s&amp;amp;source=web&amp;amp;cd=4&amp;amp;cad=rja&amp;amp;uact=8&amp;amp;ved=0CCsQFjADahUKEwiW9b_tiNXIAhWCbB4KHb6oDBA&amp;amp;url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FKalman_filter&amp;amp;usg=AFQjCNEN1xRr0hrNRhPHUMGQ_eWCws60CA&amp;amp;sig2=G1o4RCdqnRXSgX1LLMSooQ&quot;&gt;Kalman Filtering&lt;/a&gt;).&lt;/p&gt;

&lt;h2 id=&quot;writing-software-to-convert-voltage-into-temperature-readings&quot;&gt;Writing software to convert voltage into temperature readings&lt;/h2&gt;

&lt;p&gt;If we think of the system as a whole, the input to the system is Vo which is measured on an analog input pin  of the BBB.  Based on this voltage reading, we have to write software which estimates the temperature.&lt;/p&gt;

&lt;p&gt;To begin, we know that the thermister (R_2) changes resistance values depending on temperature.  We can then use the voltage devider to map this relation:&lt;/p&gt;

\[V_o = \frac{R_2 V_{in}}{R_1 + R_2}\]

&lt;p&gt;Vin in this case will be 3.3 V which is provided from the BBB.  As noted in the last post, the spec on the BBB states that that analog input pin can only take in voltage in the range of 0 to 1.8 V.  This means we can set the max Vout = 1.8.  Finally based on the resistance to temperature data, we know that resistance increases as the temperature decreases.  This means that R_2 (the resistance of the thermistor), will be the greatest when T = 0 degrees (R_2 will be around 327 kohms.  We can then use this in our voltage divider equation and solve for R_1.  The solution is R_1 =  272700 ohms.  Because resistors come in standard sizes, 274K ohm is the stardard 1% error resistor to use.  Technically, in this case we should go to the next highest resistor value (to limit the voltage to 1.8V), this doesn’t necessarily have to be true since we will not be cooling the batteries lower than room temperature.  While I recommend using the 274k ohm resistor (with 1% error), one can use a 270k ohm (with 5% error) without much concequece if they ensure that the temperature does not fall below 5 degrees.  Even if it does, the Beaglebone has some circuity to help prevent damamge for a slightly larder analog input voltage.&lt;/p&gt;

&lt;p&gt;We can use algebra to solve for R_2 in terms of the other variables as the following:&lt;/p&gt;

&lt;p&gt;\(R_2 = \frac{R_1 V_o}{V_{in} - V_o}\) where \(V_{in} \neq V_o\)&lt;/p&gt;

&lt;p&gt;In this equation, R_2 can be solved from R_1 (set by us, V_o (measured), V_in (set to by us).&lt;/p&gt;

&lt;p&gt;Next we can use the previous curve fit equation, and use algebra solve for temperature:&lt;/p&gt;

&lt;p&gt;\(temperature = - \frac{ln (\frac {R_2-c}{a}}{b}\) where \(R_2 &amp;gt; c\)$$&lt;/p&gt;

&lt;p&gt;We can then substitute our relation of R_2 to the measured Vo to get the following equation:&lt;/p&gt;

&lt;p&gt;\(temperature = -ln (\frac {\frac{R_1 V_o}{V_{in} - V_o}-c}{ab}\) where \(R_2 &amp;gt; c\) and \(V_{in} \neq V_o\)$$&lt;/p&gt;

&lt;p&gt;Before we can use this, we have to ensure the conditions hold.  V_o will on equal V_in if R_2 is equal to zero, and we also ensure C (about 5.5 kohm) &amp;gt; R_2.  If we use the data found in the csv, we see that the smallest resistance in our operaterting temperature (100 C) is 6.7100 kohm, so we are safe for both conditions.&lt;/p&gt;

&lt;h1 id=&quot;results&quot;&gt;Results!&lt;/h1&gt;

&lt;p&gt;We can now write a simple which takes the a volatage as a parameter, and returns the temperature.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;voltage_to_temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;voltage_reading&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;r_1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;274&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#kohm
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;v_in&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;3.3&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;#Volts
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;2.94311453&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;pow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;4.51009053&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;pow&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;5.054388390&lt;/span&gt;
    
    &lt;span class=&quot;n&quot;&gt;r_2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r_1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;voltage_reading&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v_in&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;voltage_reading&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;# kohm
&lt;/span&gt;    
    &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r_2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;t&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;print&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;voltage_to_temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-2.11347171107
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We can now use this function and plot for the full range of input voltages:&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-python&quot; data-lang=&quot;python&quot;&gt;&lt;span class=&quot;n&quot;&gt;v_sweep&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;np&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;linspace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;num&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1000&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;temperature_profile&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;voltage_to_temperature&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v_sweep&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;plot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v_sweep&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;temperature_profile&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ylabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Temperature (Celcius)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;xlabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Measured Voltage (V)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;plt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;title&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Temperature vs Measured Voltage&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;iframe title=&quot;temperature-vs-measured-voltage&quot; width=&quot;600&quot; height=&quot;600&quot; frameborder=&quot;0&quot; seamless=&quot;seamless&quot; scrolling=&quot;no&quot; src=&quot;https://plot.ly/~mrandrewandrade/39.embed&quot;&gt; &lt;/iframe&gt;

&lt;p&gt;Using &lt;a href=&quot;https://plot.ly/~mrandrewandrade/39.embed&quot;&gt;this chart&lt;/a&gt; we can now test the system and measure temperature!  The next post will be about combining all the prieces and doing the testing!&lt;/p&gt;

</description>
                <link>https://mrandrewandrade.github.io/blog/2015/10/22/modeling-thermistor-using-data-science.html</link>
                <guid>https://mrandrewandrade.github.io/blog/2015/10/22/modeling-thermistor-using-data-science</guid>
                <pubDate>Thu, 22 Oct 2015 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>Designing a Battery Testing Rig</title>
                <description>&lt;h1 id=&quot;background&quot;&gt;Background&lt;/h1&gt;
&lt;p&gt;As &lt;a href=&quot;https://andrewandrade.ca/blog/2015/09/11/fydp-ess.html&quot;&gt;previously mentioned&lt;/a&gt; my fourth year design project (FYDP) involves building an energy storage system (ESS) using repurposed electric vehicle (EV) batteries.  After individual battery cells are removed from the large high voltage EV battery, the first step the project is testing the battery cells to see if they are “healthy” and ready to use.  This means we have to charge and discharge the cells while monitoring both the voltage and the temperture.  We are planning on using a BeagleBone Black (BBB) as our microcontroller (show below), and have to pick sensors to measure voltage and temperature.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;http://beagleboard.org/static/images/black_hardware_details.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;project-scope&quot;&gt;Project Scope&lt;/h1&gt;

&lt;p&gt;Since we are running lean, our goal is to try and get to stage of safetly changing and discharging the battery autonomously as quickly.  This means for our &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;minimal viable product&lt;/code&gt; (MVP), we had the following goals:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Label every battery cell with a unique identifier, and keep log of all tests and data.&lt;/li&gt;
  &lt;li&gt;Be able to autonomously charge the battery.  This means be able to stop charging when either the battery reaches 50 degrees C or the voltage accross the battery cell exceed 7.2 V.&lt;/li&gt;
  &lt;li&gt;Constantly measure voltage accross the battery over time&lt;/li&gt;
  &lt;li&gt;Constantly measure the temperature of the battery over time&lt;/li&gt;
  &lt;li&gt;Be able to autonomously discharge the battery by pressenting a simple resistive load&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These are a couple of stretch goals:&lt;/p&gt;
&lt;ol&gt;
  &lt;li&gt;Steam data online&lt;/li&gt;
  &lt;li&gt;Test Multiple Cells&lt;/li&gt;
  &lt;li&gt;Coloumb counting&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Let’s start with choosing the sensors and figuring out how to take measurements.&lt;/p&gt;

&lt;h1 id=&quot;instrumentation-and-measurement&quot;&gt;Instrumentation and Measurement&lt;/h1&gt;

&lt;h2 id=&quot;measuring-voltage&quot;&gt;Measuring Voltage&lt;/h2&gt;

&lt;p&gt;Measuring voltage using a BBB is simple: we can simply use the analog input pins on the BBB to measure voltage.  The first issue is that according the the &lt;a href=&quot;http://beagleboard.org/support/BoneScript/analogRead/&quot;&gt;BBB documentation&lt;/a&gt;, to safetly read analog values, the input voltage to the analog to digital convert (ADC) is limited to 1.8V. This means that the input voltage must be properly limited to ensure the safe operstion.  To achieve this, a simple &lt;a href=&quot;https://learn.sparkfun.com/tutorials/voltage-dividers&quot;&gt;voltage divider&lt;/a&gt; can be used (by apply Ohm’s Law \(V = I R\)).&lt;/p&gt;

&lt;h3 id=&quot;voltage-divider&quot;&gt;Voltage Divider&lt;/h3&gt;

&lt;iframe title=&quot;voltage-divider&quot; width=&quot;600&quot; height=&quot;600&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; name=&quot;voltage-divider&quot; class=&quot;eda_tool&quot; src=&quot;https://upverter.com/eda/embed/#designId=79ccecb425cbbda4,actionId=&quot;&gt;&lt;/iframe&gt;

&lt;p&gt;Based on Ohm’s Law, the circuit above can be simplified to  \(V_o= \frac{I R_2}{I ( R_1 + R_2 ) } V_{in} \), and finally to this form:&lt;/p&gt;

&lt;p&gt;\[V_o=\frac{R_2}{R_1+R_2}V_{in} \]&lt;/p&gt;

&lt;p&gt;Now given a desired \(V_o\) and known \(V_{in}\), \(R_1\) and \(R_2\) can be solved for.  We wanted the ability to read up to 30V (including contingency), and still limit the voltage to the BBB to 1.8 V. Here we use \(V_{in}=30V\) and \(V_o=1.8V\).  By setting the smaller resistor \(R_2\) in this case) to \(10k\Omega\), one can solve \(R_1=160k\).  Note, resistor come in standard resistances, so one must round to ensure the limits are sets correctly.  In this example, \(R_1\) should be rounded up not down.  Why?  Think about how the voltage devider works.&lt;/p&gt;

&lt;h3 id=&quot;how-to-not-drain-battery-while-measuring&quot;&gt;How to not drain battery while measuring&lt;/h3&gt;

&lt;p&gt;The issue with this method is that with a total resistance \(R1 + R2 = 180K\Omega\), then the total current drawn \(I_{total} ={V_{in}} / R_{total} = 30V / 180k\Omega = 1.66\times10^{-4} A\) While this is a very smal current drawn, slowly by slowly it will be drain the battery.  The way to reduce this effect is to increase the resistors, to the \(M\Omega\) range, such at that current being drawn will be very low.  The issue with this is that there will not be a minimum current which exceeds the leakage current in a pin.  In short, the current can not be too small or it will cause measurement issues.  But can this be solved?  Yes!  The trick is to add a small capacitor in parallel with the \(R_2\) resistor. This improves the readings of the voltage out, yet enables us maintain a very low current.&lt;/p&gt;

&lt;h2 id=&quot;temperature-sensors&quot;&gt;Temperature Sensors&lt;/h2&gt;

&lt;p&gt;There exist many different types of temperature sensors which function in different ways.  The choice of the temperature sensor and implmentation will be talked about in the next blog post!&lt;/p&gt;
</description>
                <link>https://mrandrewandrade.github.io/blog/2015/10/21/battery-testing.html</link>
                <guid>https://mrandrewandrade.github.io/blog/2015/10/21/battery-testing</guid>
                <pubDate>Wed, 21 Oct 2015 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>Building an Energy Storage System using Re-purposed Electric Vehicle Batteries</title>
                <description>&lt;p&gt;As I am in my final year of Mechatronics Engineering at the University of Waterloo, we must complete a &lt;a href=&quot;https://uwaterloo.ca/engineering/entrepreneurship/capstone-design&quot;&gt;Capstone Design Project&lt;/a&gt; (otherwise know as a Fourth Year Design Project or FYDP).&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Capstone Design is the culmination of the undergraduate student experience, creating a blueprint for innovation in engineering design. - Waterloo Engineering&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For my fourth year design project I am working on a very exciting project which involves building an energy storage system (ESS) using repurposed Electric Vehicle (EV) batteries. Stay tuned for more information about the project!&lt;/p&gt;

</description>
                <link>https://mrandrewandrade.github.io/blog/2015/09/11/fydp-ess.html</link>
                <guid>https://mrandrewandrade.github.io/blog/2015/09/11/fydp-ess</guid>
                <pubDate>Fri, 11 Sep 2015 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>How non-linear dynamic (chaos theory) equations describe user growth in lean startups</title>
                <description>&lt;p&gt;This is a answer I gave on quora to &lt;a href=&quot;https://www.quora.com/Lean-Startups/Do-any-non-linear-dynamic-chaos-theory-equations-describe-user-growth-in-startups&quot;&gt;this question&lt;/a&gt;: Do any non-linear dynamic (chaos theory) equations describe user growth in lean startups?&lt;/p&gt;

&lt;p&gt;I am going to generalize my answer to technology startups, but the concepts can be abstracted to most startups.&lt;/p&gt;

&lt;h1 id=&quot;introduction&quot;&gt;Introduction:&lt;/h1&gt;
&lt;p&gt;Forgetting the complex equations, lets try and make a function where only technology development and business development (for simplicity) are inputs and get user growth as an output.  If the system was linear then the more technology and the more business which goes into the company would result in more users.&lt;/p&gt;

&lt;p&gt;But in real life, user acquisition is more complex than this: Not all tech and business development is the same  and company change and pivot and users come in cycles, not linearly.  There are competitors in the market and fundamental changes in technology.  All of these will contribute to the user growth in a startup.&lt;/p&gt;

&lt;p&gt;Now lets bring in a non-linear dynamic systems model: taking the technology adoption lifecycle and constant product iteration into the picture.  If we still use the tech and business development to shows user growth, but describe the function as a chaotic system, then small changes in tech and business development results in very different user growth making the full system unpredictable.&lt;/p&gt;

&lt;p&gt;That is how chaos theory describes user grown in startups!&lt;/p&gt;

&lt;p&gt;Read the full explanation for more details with a specific strange attractor model:&lt;/p&gt;

&lt;h2 id=&quot;prerequisites&quot;&gt;Prerequisites:&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;Understand Technology Adoption Lifecycle&lt;/li&gt;
  &lt;li&gt;Understand the Pivot in terms of Lean Startups&lt;/li&gt;
  &lt;li&gt;Non-linear equations, chaos theory and strange attractors&lt;/li&gt;
  &lt;li&gt;Rössler attractor model for non-linear dynamic user growth in startups&lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;1-technolgy-adoption-lifecycle&quot;&gt;1. Technolgy Adoption Lifecycle&lt;/h1&gt;

&lt;p&gt;If you have read Geoffrey Moore’s &lt;a href=&quot;http://amzn.to/1N9VK9S&quot;&gt;Crossing the Chasm&lt;/a&gt; he describes the technology/innovation adoption lifecycle in detail as following a normal distribution or bell curve:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://qph.is.quoracdn.net/main-qimg-3005bfa31f5708c14682dcb91d4a042e?convert_to_webp=true&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;2-the-pivot&quot;&gt;2. The Pivot&lt;/h1&gt;
&lt;p&gt;Now if you have read &lt;a href=&quot;http://amzn.to/1NUsKot&quot;&gt;Running Lean&lt;/a&gt; by Ash Maurya, &lt;a href=&quot;http://amzn.to/1NUsMMU&quot;&gt;The Lean Startup&lt;/a&gt; by Eric Ries or &lt;a href=&quot;http://amzn.to/1N9XfVC&quot;&gt;The Startup Owner’s Manual&lt;/a&gt; by Steve Blank you will learn about the &lt;strong&gt;pivot&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The pivot is a “structured course correction designed to test a new fundamental hypothesis about the product, strategy, and engine of growth.”   Steve Blank defines a pivot as “changing (or even firing) the plan instead of the executive (the sales exec, marketing or even the CEO).”  The main idea behind the pivot is after building a minimal viable product (MVP) and testing it in the market, you take the feedback you got from launching the early prototype to understanding the market to hopefully finding better product-market fit in the next interation.&lt;/p&gt;

&lt;p&gt;A great example of a pivot used by a company was  &lt;a href=&quot;https://en.wikipedia.org/wiki/Groupon&quot;&gt;Groupon&lt;/a&gt;; when the company first started, it was an online activism platform called The Point.  After receiving almost no traction, the founders opened a Wordpress blog and launched their first coupon promotion for a pizzeria located in their building lobby.  Although they only received 20 redemptions, the founders realized that  their idea was significant, and had successfully empowered people to  coordinate group action in purchasing. Three years later, Groupon would grow into a billion dollar business.&lt;/p&gt;

&lt;h1 id=&quot;3-non-linear-equations-chaos-theory-and-strange-attractors&quot;&gt;3. Non-linear equations, chaos theory and strange attractors&lt;/h1&gt;
&lt;p&gt;To understand the concepts better, you can read the answer to this question:
 &lt;a href=&quot;https://www.quora.com/Briefly-what-is-chaos-theory&quot;&gt;Briefly, what is chaos theory?&lt;/a&gt; but I will summarize it here.&lt;/p&gt;

&lt;p&gt;When Newton invented calculus, scientists and methematicains were able to derive “dynamic models” of real world physical systems. For example you can model and predict the trajectory of a canon on earth (assuming no wind) very accurately  since it follows a curve determined by an ordinary differential equation that is derived from Newton’s second law.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://qph.is.quoracdn.net/main-qimg-a3aabca98f2ad4c55d6851a9c97ebb62?convert_to_webp=true&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;By understanding the initial position of the canon, its initial velocity and the acceleration force of gravity we can predict where it will land.  Even if the measurement of initial conditions are slightly incorrect, the prediction will be very close to the actual trajectory (within a couple feet/meters lets say).  But what if there is no linear equation which can govern the motion?  Let’s enter the world of Chaos Theory.&lt;/p&gt;

&lt;p&gt;In a chaotic dynamical system, a small change in initial conditions will lead to a qualitatively different  behaviour.   A great example is weather.  Choas theory was discovered by Edward Lorenz when he was making weather predictions. He used sample data of initial weather conditions (beginning of the week) to simulate future weather conditions for a week. When he did this a second time, he thought it might take too long to start from the beginning of the week so he started from the middle. What he found was that the predictions from the starting conditions of the week were very different to those that were the outcome of the conditions at the middle of the week.&lt;/p&gt;

&lt;p&gt;This system is still deterministic; if you are able to  reproduce the initial conditions exactly, it will follow the same behaviour over and over again. However, slight perturbations of the  initial conditions lead to very different trajectories.&lt;/p&gt;

&lt;p&gt;Now take the animation below.&lt;/p&gt;

&lt;iframe width=&quot;420&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/AhrhpfN91po&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;

&lt;p&gt;Let’s say a simple equation when plotted at a certain point of time looked like the following:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://raw.githubusercontent.com/petroleum101/figures/master/lorenz_attractor/top_left_axis.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;What is unique is that the line goes back upon itself.  At one instant you are at the top right left (Figure above), the next you are at the bottom right (figure below)&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://raw.githubusercontent.com/petroleum101/figures/master/lorenz_attractor/bottom_right_axis.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;If the top left represented sunny, hot and humid and bottom right represented cloudy, cold and dry, what makes the system chaotic is that a small change in the input would result in a very different output.  For example, a change of 0.5 in the current temperature reading after 6 time periods for example shown in the figure blow would be a completely different forecast (hot and humid vs dry and cold)  and a seemly random output.  This is the  so called “butterfly effect”.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://qph.is.quoracdn.net/main-qimg-672cabba49bf4be15ed119b49e0e688e?convert_to_webp=true&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;If the dynamic system model evolves through phase space in a way which appears to repeat (called a &lt;a href=&quot;https://en.wikipedia.org/wiki/Fractal&quot;&gt;Fractal&lt;/a&gt; in mathematics), then the system of equations which describes its motion can be described a &lt;a href=&quot;https://en.wikipedia.org/wiki/Attractor#Strange_attractor&quot;&gt;Strange Attractor&lt;/a&gt;  (there is a more formal mathematical definition, unnecessary for this explanation).&lt;/p&gt;

&lt;h1 id=&quot;4-combining-the-concepts-1-and-2-to-form-the-rössler-attractor-model&quot;&gt;4. Combining the concepts 1 and 2 to form the Rössler Attractor Model**&lt;/h1&gt;

&lt;p&gt;So if you combine the technology adoption cycle with the idea of a pivot, every-time a startup company pivots, their company/product has a new addressable market and follows a the bell curve described by the technology adoption lifecycle.&lt;/p&gt;

&lt;p&gt;This can be modeled using a &lt;a href=&quot;https://en.wikipedia.org/wiki/R%C3%B6ssler_attractor&quot;&gt;Rössler attractor&lt;/a&gt; shown below to described the non-linear dynamic user growth in startups.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://qph.is.quoracdn.net/main-qimg-c987b6b9d42e981174d0d1e4f187b867?convert_to_webp=true&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;You can think of the z axis as user acquisition, and the x and y axis as technology and business development.  After putting in some initial tech and business development, when a startup their first MVP, then have a certain adressable market where they are able to get customers.  This can be seen by a curve describing the small jump in user acquisition.   As companies iteratate their product, their user aquistion will (ideally) increase  as described by the model.&lt;/p&gt;

&lt;p&gt;Realistically though, in one iteration of the pivot, only part of the technology development cycle will be reached so in reality the model describing real life user acquisition would be much more complex variation of the Rössler attractor.&lt;/p&gt;

&lt;p&gt;The point is that with very small changes in the technology development (a specific bug or feature) or business development (one sales deal or one marketing campaign which goes viral), there would be an unpredictable change in user acquisition (as modelled in this example).&lt;/p&gt;

&lt;p&gt;Also of note, most people talk about the butterfly effect or chaos theory as a sort of a misnomer. It isn’t “small changes will cause large effects” but Chaos is more actually “small changes lead to unpredictability”.   So if user acquisition can be modelled with a strange attractor such as the Rössler attractor, what the model is saying is that it is practically impossible to predict/model the success of a startup (or use growth) even if you have full control on the technology and business development.&lt;/p&gt;

&lt;p&gt;Hope this makes sense!&lt;/p&gt;

&lt;p&gt;For fun here is a nice render of the Rössler attractor.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://qph.is.quoracdn.net/main-qimg-3b823ec721f4fb440b741b7836ca034b?convert_to_webp=true&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;
</description>
                <link>https://mrandrewandrade.github.io/blog/2015/09/07/chaos-theory-and-user-growth-in-lean-startups.html</link>
                <guid>https://mrandrewandrade.github.io/blog/2015/09/07/chaos-theory-and-user-growth-in-lean-startups</guid>
                <pubDate>Mon, 07 Sep 2015 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>Growing and Scaling High Performance Teams</title>
                <description>&lt;p&gt;This is a cross-post of a blog post originally written for CBET’s &lt;a href=&quot;https://uwaterloo.ca/conrad-business-entrepreneurship-technology/blog/post/scaling-your-startup-team-and-knowledge&quot;&gt;Leadership Blog&lt;/a&gt; during my &lt;a href=&quot;https://uwaterloo.ca/conrad-business-entrepreneurship-technology/undergraduate-students/enterprise-co-op&quot;&gt;enterprise co-op term&lt;/a&gt; (intern at my own company) in the summer of 2014.  The blog post was also featured on LinkedIn’s &lt;a href=&quot;https://www.linkedin.com/pulse/20140816182325-143036205-growing-and-scaling-high-performance-teams?trk=prof-post&quot;&gt;Leadership and Management Pulse&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When I started &lt;a href=&quot;http://petropredict.com&quot;&gt;PetroPredict&lt;/a&gt; with Dominic, we were just a team of two co-founders looking to use technologies we used in tech companies and Silicon Valley to optimize decision making in the oil and gas industry. Since then we added on 4 others, effectively tripling our team. Over the past couple of months we were able to run a high performance team enabling our company to grow and scale.&lt;/p&gt;

&lt;h1 id=&quot;new-skillset-as-a-leader&quot;&gt;New Skillset as a Leader&lt;/h1&gt;

&lt;p&gt;Leading and building high performance teams was new to me, but as any new skill, with effort, it is possible to acquire. The very best thing about being a leader is you can reflect on leadership and management that you have experienced while working in previous roles. By reflecting on the techniques used by your previous managers, you can effectively outline what techniques you would like to use. Over my work terms in highschool co-op, summer jobs and university co-op I had a great opportunity to work in different corporate environment and with many different leaders and mentors. Learning from the past is one of the best ways to optimize the future.&lt;/p&gt;

&lt;h1 id=&quot;startup--growth&quot;&gt;Startup = Growth&lt;/h1&gt;

&lt;blockquote&gt;
  &lt;p&gt;A startup is a company designed to grow fast.” — Paul Graham&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The biggest thing that a startup has is the ability to grow and scale. It is obvious that companies can scale in technology, customers and sales, but almost every aspect of a startup has to scale. A great example of this is when &lt;a href=&quot;http://en.wikipedia.org/wiki/Chris_Cox_(Facebook)&quot;&gt;Chris Cox&lt;/a&gt; (Chief Product Officer at Facebook) told me about the idea of scaling company culture from a handful of employees to a couple of thousand.&lt;/p&gt;

&lt;h1 id=&quot;growing-knowledge&quot;&gt;Growing Knowledge&lt;/h1&gt;

&lt;p&gt;One aspect I wanted to elaborate on is growing knowledge. Working at a startup means that you are going to have to take many roles and have a diverse number of skills. The other thing is that the company is moving so fast that you have to gain required skills as soon as possible. When new members come on the team they have to gain certain knowledge before they can contribute. Even if you take an iterative approach, where you learn a little, do a little, it can still be difficult for rapid knowledge acquirement at the speed of the start up.&lt;/p&gt;

&lt;h1 id=&quot;udacity-and-moocs&quot;&gt;Udacity and MOOCs&lt;/h1&gt;

&lt;p&gt;A great solution to this is by the use of &lt;a href=&quot;https://en.wikipedia.org/wiki/Massive_open_online_course&quot;&gt;MOOCs&lt;/a&gt; (massively open online courses). We are lucky to be in a time where there is free access to very useful courses. Specifically I found that Udacity was one of the very best ways to allow team members to gain knowledge they needed to suceed.&lt;/p&gt;

&lt;p&gt;For example when our highschool summer student, &lt;a href=&quot;http://www.linkedin.com/pub/kevin-peng/9b/7b3/346&quot;&gt;Kevin Peng&lt;/a&gt;, joined the team, he never used &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git&lt;/code&gt; or version control before. Instead of having to spend time on reading boring documentation or a &lt;a href=&quot;https://git-scm.com/book/en/v2&quot;&gt;book on git&lt;/a&gt;, he made his own version of 2048 in a couple of hours by taking &lt;a href=&quot;https://www.udacity.com/course/ud248&quot;&gt;Udacity’s course&lt;/a&gt;. This fun iterative approach allowed him to have a great summer co-op experience and enabled to complete a &lt;a href=&quot;https://github.com/kevinpeng7/Data-Dumper&quot;&gt;technically difficult project&lt;/a&gt;.&lt;/p&gt;

&lt;h1 id=&quot;eating-your-own-dogfood&quot;&gt;Eating your own dogfood&lt;/h1&gt;

&lt;p&gt;A great philosophy I learnt at Facebook is the idea of “eating your own dog food”, or using your own product to validate the quality and capabilities of the product. While we do use data informed decision making techniques in running the company, this also can be applied to being a leader. Being a leader means setting an example to others, so throughout the term, I used Udacity to scale my own knowledge.&lt;/p&gt;

&lt;p&gt;It began by taking Steve Blank’s course on &lt;a href=&quot;https://www.udacity.com/course/ep245&quot;&gt;How to Build a Startup&lt;/a&gt;, and was able to apply the teachings to my own start up. One of the biggest learnings was the idea of minimal viable product and market validation. By taking the advice from the course, we were able to make demos and presentations and found many other applications for our technology which companies are very interested in.&lt;/p&gt;

&lt;p&gt;As &lt;a href=&quot;http://ca.linkedin.com/in/jonathanestrella&quot;&gt;Jonathan Estralla&lt;/a&gt; (our software developer) and I found, Udacity provides many other courses in topics such and data science, web development, and even machine learning. Udacity really helps scale knowledge as every lesson is a very short video (usually less than 5 minute) and has quick quizzes and application based assignments. Sometimes there are only a couple of topics we would need to brush up on, we could just watch specific topics which allowed us to complete the task at hand. Udacity in combination of other online resources enables our team to gain the required skills to be successful.
Running Mean, Lean and Agile&lt;/p&gt;

&lt;p&gt;Running lean and agile as now become colloquial in software development and startups and is fundamental to running high performance teams. The biggest idea behind these techniques is another Facebook philosophy: &lt;strong&gt;focus on impact&lt;/strong&gt;. Understanding what is the most important and valuable thing at the moment and executing as quick as you can. Here are some techniques I found to be useful for running high performing teams by running lean and Agile:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Beginning of term goal setting&lt;/strong&gt; – Get team members to set goals in the beginning of the term, and help motivate them to achieve their goals&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Weekly reports&lt;/strong&gt; – At the end of the week do a quick summary of what was worked on during the week and set goals for the next week.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Weekly meetings&lt;/strong&gt; – At the beginning of the week, summarize what went on last week and the high level goals for this week. This is also a great opportunity to talk about company news&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Daily goals&lt;/strong&gt; – Daily scrum meetings or stand ups can be used effectively to get to low level goal setting. It also provides an opportunity for members talk about issues or roadblocks they are facing or opportunities for collaboration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;http://asana.com&quot;&gt;Asana&lt;/a&gt;&lt;/strong&gt; – Asana is a great product management and collaboration tool. It works great as our team works remotely&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Company wiki&lt;/strong&gt; – Setting up and running a central source of knowledge for the company enables quick collaboration and opportunity for knowledge capture&lt;/p&gt;

&lt;h1 id=&quot;the-most-powerful-technique-of-all&quot;&gt;The Most Powerful Technique of All&lt;/h1&gt;

&lt;p&gt;Finally, the biggest take away from running a startup is learning from the past by getting advice from mentors and experts. Using information from the past to make better decisions is one of the most powerful things anyone can do.&lt;/p&gt;

&lt;p&gt;Throughout the term I have been fortunate to get advice from many mentors from the the &lt;a href=&quot;http://uwaterloo.ca&quot;&gt;University of Waterloo&lt;/a&gt;, the &lt;a href=&quot;http://velocity.uwaterloo.ca&quot;&gt;Velocity Program&lt;/a&gt;, the &lt;a href=&quot;https://uwaterloo.ca/conrad-business-entrepreneurship-technology/&quot;&gt;Conrad Business, Entrepreneurship and Technology Centre&lt;/a&gt;, companies out of the &lt;a href=&quot;http://velocity.uwaterloo.ca/workspaces/velocity-garage/&quot;&gt;Velocity Garage&lt;/a&gt; and many work colleges and friends. While I do not have room here to name everyone, I wanted to thank everyone for their help and support throughout the term!&lt;/p&gt;

</description>
                <link>https://mrandrewandrade.github.io/blog/2014/08/16/growing-teams.html</link>
                <guid>https://mrandrewandrade.github.io/blog/2014/08/16/growing-teams</guid>
                <pubDate>Sat, 16 Aug 2014 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>Tools to get things done!</title>
                <description>&lt;h1 id=&quot;tools-i-use&quot;&gt;Tools I use&lt;/h1&gt;

&lt;p&gt;Most of the tools I use can be found in my &lt;a href=&quot;https://backpak.io/u/MrAndrewAndrade&quot;&gt;backpak&lt;/a&gt;&lt;/p&gt;

&lt;h1 id=&quot;wishlist&quot;&gt;Wishlist&lt;/h1&gt;

&lt;p&gt;&lt;a href=&quot;http://www.amazon.ca/gp/product/B00IU4JM52/ref=as_li_ss_tl?ie=UTF8&amp;amp;camp=15121&amp;amp;creative=390961&amp;amp;creativeASIN=B00IU4JM52&amp;amp;linkCode=as2&amp;amp;tag=mrandrewandra-20&quot;&gt;Battery Replacement&lt;/a&gt;&lt;/p&gt;
</description>
                <link>https://mrandrewandrade.github.io/blog/2014/07/01/tools.html</link>
                <guid>https://mrandrewandrade.github.io/blog/2014/07/01/tools</guid>
                <pubDate>Tue, 01 Jul 2014 00:00:00 +0000</pubDate>
        </item>

        <item>
                <title>How I won $5000 at a Facebook hackathon without a single line of code</title>
                <description>&lt;p&gt;&lt;em&gt;This a cross post from the&lt;/em&gt; &lt;a href=&quot;http://www.opencompute.org/&quot;&gt;&lt;em&gt;Open Compute Project&lt;/em&gt;&lt;/a&gt; &lt;a href=&quot;http://www.opencompute.org/blog/ocp-hackathon-winner-the-codeless-hack/&quot;&gt;&lt;em&gt;official blog&lt;/em&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Our second blog post about the OCP Summit’s hardware hackathon comes from Derek Jouppi and&lt;/em&gt; &lt;a href=&quot;http://ca.linkedin.com/pub/andrew-andrade/3b/a9b/6b9&quot;&gt;&lt;em&gt;Andrew Andrade&lt;/em&gt;&lt;/a&gt; &lt;em&gt;who are interns at Facebook and won the OCP Summit Hackathon with a new design for the &lt;a href=&quot;http://www.opencompute.org/wiki/Open_Rack&quot;&gt;Open Rack&lt;/a&gt; V2’s Battery Backup Unit.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Derek and I decided to take part in the hardware hackathon at the Open Compute Summit on a whim. We’d heard about the hackathon and were intrigued enough to stop by, but didn’t plan on joining in. Once we were there, however, we realized that the opportunity was too much to pass up, and we jumped in without the team size and equipment that many other groups had.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;We didn’t come with a team, or had years of experience.  We have something better: an idea and killer execution.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1 id=&quot;the-idea&quot;&gt;The Idea&lt;/h1&gt;
&lt;p&gt;We wanted to build something that was highly impactful, that could be contributed immediately to Open Compute, and that we hoped would be a shippable prototype within 24 hours. Given our criteria, we decided we wanted to do a hack for the newly released Battery Backup Unit (BBU) on the Open Rack V2 design, since this is the area that Derek was most familiar with.&lt;/p&gt;

&lt;p&gt;The problem with the BBU is that if it is not functional, debugging a failed unit is extremely difficult and time consuming. You have to use a nest of wires, probes, DMM, and/or oscilloscope to find the solution – and it’s definitely not a great solution. Instead, we envisioned a coupler that would take in the output from the scope, process the signals and intelligently display what the error was. Using a simple ATMEGA microcontroller, and LED display and a few other components, we could make a compact and intelligent tool for technicians working in data centers. It was simple enough we could design and build a working prototype in only 24 hours, and yet it had high impact as it could directly contribute to running a better data center. It seemed like a perfect project for our two-man team.&lt;/p&gt;

&lt;p&gt;Thanks to one of the hackathon’s organizers, John Kenevey, we were able to run back to Menlo Park to grab the supplies we needed: two Arduinos, bread breadboards, LED’s, wires, DMM, and an assortment of other parts we thought might be useful.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://andrewandrade.ca/blog/images/preparing-to-win-hackathon.jpg&quot; alt=&quot;&quot; /&gt;&lt;br /&gt;
&lt;strong&gt;Derek Jouppi and I begin to assemble the equipment we need for our hack.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Then we got to work. Since the display BBU’s were inaccessible, I quickly began to write Arduino code to simulate a failing BBU. I also wrote some code that acted as a DAC to take in the signals from the BBU. Meanwhile, Derek got to work doing a pin out drawing and sketching the initial schematic. We worked for a few hours before bringing our design to an Open Rack prototype to investigate how we could implement it. That’s when we realized our solution was all wrong.&lt;/p&gt;

&lt;p&gt;Our monitoring system that sat on all the racks didn’t make sense. There was not enough room in the V2 rack to hold a coupler, and a microcontroller solution would be too expensive and not scalable in the large data center.&lt;/p&gt;

&lt;p&gt;With only a few hours left in the hackathon, we decided we needed to pivot to simplicity. We’d been working furiously to design a complex solution, when what we really needed was to take the Open Compute approach: remove anything in the data center that didn’t contribute to efficiency. In this case, we decided we wanted to create a simple, minimal device to solve the problem of bringing visibility to failing BBU’s.&lt;/p&gt;

&lt;h1 id=&quot;the-pivot&quot;&gt;The Pivot&lt;/h1&gt;

&lt;p&gt;We realized that, given the mapping of the pin outs, one solution would be to connect the signals to the status LED’s, which would give instant visualization to the problems with the BBU. While it would take manual diagnostics to determine issues, the cost of the device would be significantly lower, and it would be much easier to operate. For added functionality we included an output header. This could be used in the future to connect to a microcontroller if a more automated method had to be deployed. Finally, since the BBU relied on a power supply to charge, we included a power header that could be used to connect to the power supply.&lt;/p&gt;

&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/rrX7r5jM19A&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;&lt;strong&gt;The debug card that resulted from our hack could easily attach as a component to the back of a Battery Backup Unit as shown is this quickly rendered animation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Our hack had become a codeless debug tool that would enable techs to quickly and efficiently debug issues with battery back up units in their datacenters.&lt;/p&gt;

&lt;p&gt;After drafting out a quick design on paper, we quickly iterated our design on breadboards attempting to gain the designed functionality. We borrowed an actual failing BBU from the demo and after some iteration, we were able to come up with a very simple, “bare bones” design for the debug card.&lt;/p&gt;

&lt;iframe title=&quot;hackathon&quot; width=&quot;600&quot; height=&quot;500&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; name=&quot;hackathon&quot; class=&quot;eda_tool&quot; src=&quot;https://upverter.com/eda/embed/#designId=67c971c45790061b,actionId=&quot;&gt;&lt;/iframe&gt;
&lt;p&gt;&lt;strong&gt;Schematic of the debug card we made using Upverter’s schematic layout tool.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;EDIT&lt;/strong&gt;: The interactive &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;iframe&lt;/code&gt; is breaking will all the traffic, you can view the &lt;a href=&quot;https://upverter.com/mrandrewandrade/53180db3a9c16395/hackathon/&quot;&gt;schematic here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For our circuit layout we used Upverter, a start-up that focuses on online board design CAD software. We drew up a quick schematic by sourcing our components online and imported their drawings on Upverter’s schematic tool. We then used the tool to create a bill of materials that included the component prices and the cost to spin the board.&lt;/p&gt;

&lt;p&gt;We then created a PCB layout for the board. To parallelize our efforts, we performed a quick mock-up on MS Paint of the layout of the board. Derek finished up the PCB layout on Upverter while I did a quick rending of our final product using mechanical CAD software as shown below.&lt;/p&gt;

&lt;h1 id=&quot;the-demo&quot;&gt;The Demo&lt;/h1&gt;

&lt;p&gt;When we demonstrated our project for the judges, we were proud to watch as the BBU powered up and our LED’s lit up a split second later, indicating the status of the unit. Our simple solution had made it easy and inexpensive to know if the BBU was functional at any given time. This vital information will make it easier to be sure that any power loss won’t result in a loss of functionality.&lt;/p&gt;

&lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/KAKc50apXxI&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;

&lt;p&gt;We were incredibly excited by what we’d built, and we couldn’t help but note the community spirit of Open Compute that had gotten us there. Throughout the hack, we frequently traded tools with other teams and asked other participants for their input as we worked. Everyone lived and breathed the open source philosophy – that sharing knowledge and experience will result in better hacks overall. It seems to us that this desire to collaborate is what Open Compute is all about, and in that vein, we plan to release the specifications for our BBU hack to the open source community in the next few weeks.&lt;/p&gt;

</description>
                <link>https://mrandrewandrade.github.io/blog/2014/03/14/codeless-hackathon-winner.html</link>
                <guid>https://mrandrewandrade.github.io/blog/2014/03/14/codeless-hackathon-winner</guid>
                <pubDate>Fri, 14 Mar 2014 00:00:00 +0000</pubDate>
        </item>


</channel>
</rss>
