<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ calculus - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ calculus - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Mon, 25 May 2026 05:06:48 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/calculus/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ Learn Calculus 2 in This Free 7-Hour Course ]]>
                </title>
                <description>
                    <![CDATA[ There are many types of software development that require high level mathematics such as graphics simulations and some types of machine learning.  We are helping people learn the mathematics they need by posting a series of college-level courses on t... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/learn-calculus-2-in-this-free-7-hour-course/</link>
                <guid isPermaLink="false">66b20414903dc07a13516661</guid>
                
                    <category>
                        <![CDATA[ Advanced Mathematics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ calculus ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Math ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Mathematics ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Beau Carnes ]]>
                </dc:creator>
                <pubDate>Mon, 14 Sep 2020 13:38:29 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/09/calc2.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>There are many types of software development that require high level mathematics such as graphics simulations and some types of machine learning. </p>
<p>We are helping people learn the mathematics they need by posting a series of college-level courses on the freeCodeCamp.org YouTube channel. Our latest free course is a complete 7-hour Calculus 2 course.</p>
<p>This  course was created by Dr. Linda Green who teaches at the University of  North Carolina at Chapel Hill. She has years of experience teaching Calculus 2 to undergraduate students. </p>
<p>Besides the video content, we have also included full course notes from Dr. Green as a link in the video description.</p>
<p>Below are all the Calculus 2 concepts you will learn about in this course. </p>
<ul>
<li>Area Between Curves</li>
<li>Volumes of Solids of Revolution</li>
<li>Volumes Using Cross-Sections</li>
<li>Arclength</li>
<li>Work as an Integral</li>
<li>Average Value of a Function</li>
<li>Proof of the Mean Value Theorem for Integrals</li>
<li>Integration by Parts</li>
<li>Trig Identities</li>
<li>Proof of the Angle Sum Formulas</li>
<li>Integrals Involving Odd Powers of Sine and Cosine</li>
<li>Integrals Involving Even Powers of Sine and Cosine</li>
<li>Special Trig Integrals</li>
<li>Integration Using Trig Substitution</li>
<li>Integrals of Rational Functions</li>
<li>Improper Integrals - Type 1</li>
<li>Improper Integrals - Type 2</li>
<li>The Comparison Theorem for Integrals</li>
<li>Sequences - Definitions and Notation</li>
<li>Series Definitions</li>
<li>Sequences - More Definitions</li>
<li>Monotonic and Bounded Sequences Extra</li>
<li>L'Hospital's Rule</li>
<li>L'Hospital's Rule on Other Indeterminate Forms</li>
<li>Convergence of Sequences</li>
<li>Geometric Series</li>
<li>The Integral Test</li>
<li>Comparison Test for Series</li>
<li>The Limit Comparison Test</li>
<li>Proof of the Limit Comparison Test</li>
<li>Absolute Convergence</li>
<li>The Ratio Test</li>
<li>Proof of the Ratio Test</li>
<li>Series Convergence Test Strategy</li>
<li>Taylor Series Introduction</li>
<li>Power Series</li>
<li>Convergence of Power Series</li>
<li>Power Series Interval of Convergence Example</li>
<li>Proofs of Facts about Convergence of Power Series</li>
<li>Power Series as Functions</li>
<li>Representing Functions with Power Series</li>
<li>Using Taylor Series to find Sums of Series</li>
<li>Taylor Series Theory and Remainder</li>
<li>Parametric Equations</li>
<li>Slopes of Parametric Curves</li>
<li>Area under a Parametric Curve</li>
<li>Arclength of Parametric Curves</li>
<li>Polar Coordinates</li>
</ul>
<p>We recommend you pull out some paper and a pencil and take physical notes – just like when you were back in a classroom.</p>
<p>This manual process of taking notes will help you better comprehend and  retain these concepts, since Dr. Green moves fast and covers a lot of  topics in a short time.</p>
<p>Check out our <a target="_blank" href="https://www.youtube.com/playlist?list=PLWKjhJtqVAbl5SlE6aBHzUVZ1e6q1Wz0v">mathematics playlist</a> if you want to brush up on the prerequisites such as Algebra, Precalculus, and Calculus 1.</p>
<p>You can watch the <a target="_blank" href="https://www.youtube.com/watch?v=7gigNsz4Oe8">full course on the freeCodeCamp.org YouTube channel</a> (7-hour watch).</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Unit Circle Chart and Trig Calculator – Cos 0, Sin 0, Tan 0, Radians and More ]]>
                </title>
                <description>
                    <![CDATA[ By Alexander Arobelidze The unit circle is a useful visualization tool for learning about trigonometric functions.  The key to its usefulness is its simplicity. It removes the need for memorizing different values and allows the user to simply derive ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/unit-circle-chart-and-trig-calculator/</link>
                <guid isPermaLink="false">66d45d6bc17d4b8ace5b9eb6</guid>
                
                    <category>
                        <![CDATA[ Advanced Mathematics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ calculus ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Math ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Mathematics ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 08 Sep 2020 16:06:31 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9c98d8740569d1a4ca1c60.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Alexander Arobelidze</p>
<p>The <strong>unit circle</strong> is a useful visualization tool for learning about trigonometric functions. </p>
<p>The key to its usefulness is its simplicity. It removes the need for memorizing different values and allows the user to simply derive different results for different cases. </p>
<p>Let's learn more about it and test our understanding with a handy trigonometric calculator I created at the end of the article.</p>
<h2 id="heading-part-1-what-is-the-unit-circle-and-how-is-it-used">Part 1. What is the Unit Circle and how is it used?</h2>
<p>The unit circle is a circle with a radius of <strong>one</strong> unit with its center placed at the origin. In other words, the center is put on a graph where the <strong>X</strong> and <strong>Y</strong> axes cross. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/unitCircle1-1.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Fig 1</strong>. The graph of the unit circle with radius = 1 and points of intersection with X and Y axes</em></p>
<p>Having a radius equal 1 unit will allow us to create <strong>reference triangles</strong> with hypotenuse equal to 1 unit. </p>
<p>As we will see shortly, that allows us to measure <strong>sine</strong>, <strong>cosine</strong> and <strong>tangent</strong> directly. The triangle below reminds us how we define sine and cosine for some angle <strong>alpha</strong>. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/unitCircle2.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Fig 2</strong>. Geometric definition of sine and cosine for an angle with hypotenuse equal 1</em></p>
<p>Since the hypotenuse equals 1 and anything divided by 1 equals itself, sin of alpha equals the length of BC. Or <strong>sin(α) = BC/1 = BC</strong>. </p>
<p>Similarly, cosine will equal the length of AC. Or <strong>cos(α) = AC/1 = AC</strong>. </p>
<p>Next, let's move this triangle into our Unit Circle, so the radius of the circle can serve as the hypotenuse.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/unitCircle3.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Fig 3</strong>. Reference triangle inside Unit Circle. x coordinate = cos(α) and y coordinate = sin(α)</em></p>
<p>As a result, the <strong>y</strong> coordinate of the point where the triangle touches the circle equals sin(α), or <strong>y = sin(α)</strong>. Similarly, the <strong>x</strong> coordinate will equal cos(α), or <strong>x = cos(α)</strong>. </p>
<p>Thus, by moving around the circle and changing the angle, we can measure sine and cosine of that angle by measuring the y and x coordinates accordingly. </p>
<p>The angles can be measured in <strong>degrees</strong> and/or <strong>radians</strong>. The point with coordinates (1, 0) corresponds with <strong>0</strong> degrees (see Fig 1). The measure increases in a counterclockwise direction, so the point with coordinates (0, 1) will correspond with <strong>90</strong> degrees. A complete circle – <strong>360</strong> degrees. </p>
<h2 id="heading-part-2-important-angles-and-their-corresponding-sine-cosine-and-tangent-values">Part 2. Important angles and their corresponding sine, cosine and tangent values</h2>
<p>Since it makes sense to start at 0 degrees, our circle will look like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/unitCircle4.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Fig 4</strong>. Unit circle showing cos(0) = 1 and sin(0) = 0</em></p>
<p> Because <strong>tangent</strong> equals sine divided by cosine, <strong>tan(0) = sin(0) / cos(0) = 0 / 1 = 0</strong>. </p>
<p>Next let's see what happens at 90 degrees. The coordinates of the corresponding point are (0, 1). Thus, sin(90) = y = 1 and cos(90) = x = 0. The circle will look like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/unitCircle5.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Fig 5</strong>. Unit circle showing cos(90) = 0 and sin(90) = 1</em></p>
<p>What about tangent(90)? As the cosine measure approaches 0, and it happens to be a denominator in a fraction, the value of that fraction increases to infinity. Therefore <strong>tan(90) is said to be undefined</strong>. </p>
<p>Now the question you might ask: as sin goes from 0 to 1 while cosine goes from 1 to 0, do they ever equal each other? The answer is yes, and that happens exactly half way at 45 degrees! The circle looks like this:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/unitCircle6.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Fig 6</strong>. Unit circle showing sin(45) = cos(45) = 1 / √2</em></p>
<p>As a result of the numerator being the same as the denominator, <strong>tan(45) = 1</strong>.</p>
<p>Finally, the general reference Unit Circle. It reflects both positive and negative values for X and Y axes and shows important values you should remember</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/08/unitCircle7.png" alt="Image" width="600" height="400" loading="lazy">
<em><strong>Fig 7</strong>. Unit circle showing important sine and cosine values to remember</em></p>
<p>As a final note for this section, it always helps to remember the following trigonometric identity based on the <a target="_blank" href="https://en.wikipedia.org/wiki/Pythagorean_theorem">Pythagorean theorem</a>: sin<sup>2</sup>(α) + cos<sup>2</sup>(α) = 1. </p>
<h2 id="heading-part-3-trigonometric-calculator">Part 3. Trigonometric Calculator</h2>
<p>As a useful practice tool, I have added a simple trigonometric calculator. It takes inputs for angle measures and outputs corresponding values for <strong>sine</strong>, <strong>cosine</strong> and <strong>tangent</strong> functions. </p>
<p>You can choose <strong>degrees</strong> or <strong>radians</strong> as a measure of angle. They each have their advantages and disadvantages. For quantitative relationships, since <strong>π</strong> radians <strong>=</strong> 180°, <strong>1 radian</strong> would be 180°/<strong>π</strong> or roughly <strong>57°</strong>. It can be calculated with any desired accuracy.   </p>
<p>The code for the calculator contains some basic interactivity and error handling within constraints of the editor. Its building blocks are marked and commented so anyone with the desire to modify it can easily do so. </p>
<p>For example, new functions such as <strong>ctg</strong>, <strong>sec</strong> and so on can be added as well as different color schemes and much more. The complete source code can be accessed by <a target="_blank" href="https://github.com/sandroarobeli/TrigCalculator/blob/master/TrigCalculator.txt">clicking here</a>.</p>

<div class="flex-container">
    <div class="row">
        <h3 id="heading-input-degree-or-radian-measure-and-click-submit">
            Input degree or radian measure and click Submit
        </h3>
    </div>
    <div class="row">
        <div>
            
        </div>
        <div>
             <div>
                     <div>
                          
                          
                            Degree
                        
                    </div>
                    <div>
                          
                           
                             Radian
                         
                    </div>
             </div>
         </div>
         <div>
             
                Submit
                    
            
         </div>
    </div>
    <div class="row">
        <div>
            <h3 id="">
                SIN: 
                    <span id="sin"></span>
            </h3>
        </div>
        <div>
            <h3 id="">
                COS: 
                    <span id="cos"></span>
            </h3>
        </div>
        <div>
            <h3 id="">
                TAN: 
                    <span id="tan"></span>
            </h3>
        </div>
    </div>
    <div class="row">
        <h3 id="prompter"></h3>
    </div>
 </div>








<p>I hope the article, along with the calculator source code, will benefit you. Looking forward to seeing its modifications soon.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Learn Calculus 1 in This Free 12-Hour Course ]]>
                </title>
                <description>
                    <![CDATA[ Calculus concepts are important to understand for many types of software development.  Calculus is often used when developing algorithms for modeling real-word phenomena. It is also used in graphics and physics simulations, which are key parts to man... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/learn-college-calculus-in-free-course/</link>
                <guid isPermaLink="false">66b20416a8b92c9329236488</guid>
                
                    <category>
                        <![CDATA[ calculus ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Math ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Beau Carnes ]]>
                </dc:creator>
                <pubDate>Thu, 27 Aug 2020 14:11:48 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/08/calculus.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Calculus concepts are important to understand for many types of software development. </p>
<p>Calculus is often used when developing algorithms for modeling real-word phenomena. It is also used in graphics and physics simulations, which are key parts to many video games. Calculus is also used in the field of machine learning.</p>
<p>We have posted a 12-hour <a target="_blank" href="https://www.youtube.com/watch?v=HfACrKJ_Y2w">college Calculus course</a> on the freeCodeCamp.org YouTube channel.</p>
<p>This  course was created by Dr. Linda Green who teaches at the University of  North Carolina at Chapel Hill. She has years of experience teaching Calculus to undergraduate students. </p>
<p>This course actually combines two courses taught by Dr. Green. She teaches both Calculus 1 and a Calculus 1 Corequisite course, designed to be taken at the same time. </p>
<p>In this video, the lectures from the Corquisite course, which review important Algebra and Trigonometry concepts, have been interspersed with the Calculus 1 lectures at the places suggested by Dr. Green.</p>
<p>Below are all the Calculus concepts you will learn about in this course. The sections from the Corequisite course are identified.</p>
<ul>
<li>[Corequisite] Rational Expressions</li>
<li>[Corequisite] Difference Quotient</li>
<li>Graphs and Limits</li>
<li>When Limits Fail to Exist</li>
<li>Limit Laws</li>
<li>The Squeeze Theorem</li>
<li>Limits using Algebraic Tricks</li>
<li>When the Limit of the Denominator is 0</li>
<li>[Corequisite] Lines: Graphs and Equations</li>
<li>[Corequisite] Rational Functions and Graphs</li>
<li>Limits at Infinity and Graphs</li>
<li>Limits at Infinity and Algebraic Tricks</li>
<li>Continuity at a Point</li>
<li>Continuity on Intervals</li>
<li>Intermediate Value Theorem</li>
<li>[Corequisite] Right Angle Trigonometry</li>
<li>[Corequisite] Sine and Cosine of Special Angles</li>
<li>[Corequisite] Unit Circle Definition of Sine and Cosine</li>
<li>[Corequisite] Properties of Trig Functions</li>
<li>[Corequisite] Graphs of Sine and Cosine</li>
<li>[Corequisite] Graphs of Sinusoidal Functions</li>
<li>[Corequisite] Graphs of Tan, Sec, Cot, Csc</li>
<li>[Corequisite] Solving Basic Trig Equations</li>
<li>Derivatives and Tangent Lines</li>
<li>Computing Derivatives from the Definition</li>
<li>Interpreting Derivatives</li>
<li>Derivatives as Functions and Graphs of Derivatives</li>
<li>Proof that Differentiable Functions are Continuous</li>
<li>Power Rule and Other Rules for Derivatives</li>
<li>[Corequisite] Trig Identities</li>
<li>[Corequisite] Pythagorean Identities</li>
<li>[Corequisite] Angle Sum and Difference Formulas</li>
<li>[Corequisite] Double Angle Formulas</li>
<li>Higher Order Derivatives and Notation</li>
<li>Derivative of e^x</li>
<li>Proof of the Power Rule and Other Derivative Rules</li>
<li>Product Rule and Quotient Rule</li>
<li>Proof of Product Rule and Quotient Rule</li>
<li>Special Trigonometric Limits</li>
<li>[Corequisite] Composition of Functions</li>
<li>[Corequisite] Solving Rational Equations</li>
<li>Derivatives of Trig Functions</li>
<li>Proof of Trigonometric Limits and Derivatives</li>
<li>Rectilinear Motion</li>
<li>Marginal Cost</li>
<li>[Corequisite] Logarithms: Introduction</li>
<li>[Corequisite] Log Functions and Their Graphs</li>
<li>[Corequisite] Combining Logs and Exponents</li>
<li>[Corequisite] Log Rules</li>
<li>The Chain Rule</li>
<li>More Chain Rule Examples and Justification</li>
<li>Justification of the Chain Rule</li>
<li>Implicit Differentiation</li>
<li>Derivatives of Exponential Functions</li>
<li>Derivatives of Log Functions</li>
<li>Logarithmic Differentiation</li>
<li>[Corequisite] Inverse Functions</li>
<li>Inverse Trig Functions</li>
<li>Derivatives of Inverse Trigonometric Functions</li>
<li>Related Rates - Distances</li>
<li>Related Rates - Volume and Flow</li>
<li>Related Rates - Angle and Rotation</li>
<li>[Corequisite] Solving Right Triangles</li>
<li>Maximums and Minimums</li>
<li>First Derivative Test and Second Derivative Test</li>
<li>Extreme Value Examples</li>
<li>Mean Value Theorem</li>
<li>Proof of Mean Value Theorem</li>
<li>[Corequisite] Solving Right Triangles</li>
<li>Derivatives and the Shape of the Graph</li>
<li>Linear Approximation</li>
<li>The Differential</li>
<li>L'Hospital's Rule</li>
<li>L'Hospital's Rule on Other Indeterminate Forms</li>
<li>Newtons Method</li>
<li>Antiderivatives</li>
<li>Finding Antiderivatives Using Initial Conditions</li>
<li>Any Two Antiderivatives Differ by a Constant</li>
<li>Summation Notation</li>
<li>Approximating Area</li>
<li>The Fundamental Theorem of Calculus, Part 1</li>
<li>The Fundamental Theorem of Calculus, Part 2</li>
<li>Proof of the Fundamental Theorem of Calculus</li>
<li>The Substitution Method</li>
<li>Why U-Substitution Works</li>
<li>Average Value of a Function</li>
<li>Proof of the Mean Value Theorem for Integrals</li>
</ul>
<p>We recommend you pull out some paper and a pencil and take physical notes – just like when you were back in a classroom.</p>
<p>This manual process of taking notes will help you better comprehend and  retain these concepts, since Dr. Green moves fast and covers a lot of  topics in a short time.</p>
<p>Watch the <a target="_blank" href="https://www.youtube.com/watch?v=HfACrKJ_Y2w">full course on the freeCodeCamp.org YouTube channel</a> (12 hour watch).</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to tackle root finding in JavaScript ]]>
                </title>
                <description>
                    <![CDATA[ By Zaid Humayun Introduction I’ve been wanting to write about this topic for a while now. I recently had the opportunity to work on simulating the GoalSeek functionality of Excel for a web application. I found the whole purpose of GoalSeek and how it... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-tackle-root-finding-in-javascript-40d2c34507b2/</link>
                <guid isPermaLink="false">66d461d5d7a4e35e384349d1</guid>
                
                    <category>
                        <![CDATA[ calculus ]]>
                    </category>
                
                    <category>
                        <![CDATA[ JavaScript ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Mathematics ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 02 Nov 2018 16:12:22 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*UAE-xb9qHM4PuRbNc-eu3g.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Zaid Humayun</p>
<h3 id="heading-introduction">Introduction</h3>
<p>I’ve been wanting to write about this topic for a while now. I recently had the opportunity to work on simulating the GoalSeek functionality of Excel for a web application. I found the whole purpose of GoalSeek and how it works fascinating.</p>
<p>The whole purpose of GoalSeek in Excel is finding an input for an equation that will provide the desired solution. To understand how this is supposed to work, we’ll consider something really simple.</p>
<h3 id="heading-what-is-goalseek">What Is Goalseek?</h3>
<p>Let’s take the example of finding the amount due based on a principal using the Simple Interest formula.</p>
<p>The equation for the simple interest formula is, well, simple:</p>
<pre><code>A = P(<span class="hljs-number">1</span>+rt), eqn(<span class="hljs-number">1</span>)
</code></pre><pre><code>P -&gt; principalr -&gt; rate <span class="hljs-keyword">of</span> interestt -&gt; time <span class="hljs-keyword">in</span> years
</code></pre><p>We’ll set the following values:</p>
<pre><code>P -&gt; <span class="hljs-number">10000</span>r -&gt; <span class="hljs-number">7.5</span>t -&gt; <span class="hljs-number">15</span>
</code></pre><p>This gives us the amount due as being:</p>
<pre><code>A = <span class="hljs-number">10000</span>(<span class="hljs-number">1</span>+<span class="hljs-number">7.5</span>*<span class="hljs-number">15</span>) = <span class="hljs-number">1135000</span>
</code></pre><p>Now, let’s say the requirement for our solution changed. Now, instead of <em>finding the amount due</em> based on the principal, rate of interest, and time, we instead need to find the <em>rate of interest that will give us the desired amount due</em> but keeping the principal and time the same.</p>
<p>Let’s alter the example now:</p>
<pre><code>P -&gt; <span class="hljs-number">10000</span>r -&gt; ?t -&gt; <span class="hljs-number">15</span>A -&gt; <span class="hljs-number">1120000</span>
</code></pre><p>Here, we are trying to find the interest rate that will allow us to pay 1120000 instead of 1135000. We can solve this by switching the variables around.</p>
<pre><code>A = P(<span class="hljs-number">1</span>+rt) =&gt; <span class="hljs-number">1120000</span> = <span class="hljs-number">10000</span>(<span class="hljs-number">1</span>+r*<span class="hljs-number">15</span>)
</code></pre><pre><code><span class="hljs-number">1</span>+<span class="hljs-number">15</span>*r = <span class="hljs-number">1120000</span> / <span class="hljs-number">10000</span> =&gt; r = (<span class="hljs-number">112</span> - <span class="hljs-number">1</span>) / <span class="hljs-number">15</span>
</code></pre><pre><code>r = <span class="hljs-number">7.4</span>%
</code></pre><p>Brilliant! There we have it! We did something Excel’s Goalseek does.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*Dh3k5_mfbzp0ZjLr3xOvSw.gif" alt="Image" width="1000" height="396" loading="lazy">
<em>Gif capture of Excel GoalSeek functionality</em></p>
<p>One problem, though. That was a really simple equation and problem. What happens if the equation is significantly more complex and involves trigonometric functions along with multiple possible solutions? I’ll give you an example of an equation that you would be able to solve with Goalseek:</p>
<pre><code>f(x, y) = <span class="hljs-number">1550</span> - (<span class="hljs-number">4</span>*x/y * sinh(y/<span class="hljs-number">2</span> * <span class="hljs-number">1500</span> / (<span class="hljs-number">2</span>*x))), eqn(<span class="hljs-number">2</span>)
</code></pre><p>Yeah, that definitely looks like a handful. One of the daunting factors when looking at something like this for me is that things are being expressed as functions with dependent variables.</p>
<p>Wasn’t this <code>A = P(1+rt)</code> easier to look at? Granted, part of that is also the fact that the equation is a lot smaller.</p>
<p>But, what if we re-wrote it like this:</p>
<pre><code>f(P, r, t) = P(<span class="hljs-number">1</span>+rt)
</code></pre><p>See? It’s still the same thing.</p>
<p>Let’s go back to eqn(2). What if we have the following problem statement:</p>
<pre><code><span class="hljs-number">0</span> = <span class="hljs-number">1550</span> - (<span class="hljs-number">4</span>*x/<span class="hljs-number">0.022</span> * sinh(<span class="hljs-number">0.022</span>/<span class="hljs-number">2</span> * <span class="hljs-number">1500</span> / (<span class="hljs-number">2</span>*x))),solve <span class="hljs-keyword">for</span> x
</code></pre><p>Well, again, all you’re really doing is solving for a variable, but just look at how much harder the problem’s gotten. And it’s primarily because of that pesky <code>sinh</code> sitting in the equation.</p>
<p>Okay, if you’re new to this, I imagine things are getting a little overwhelming. Let’s take a step back and think about what we’ve figured out so far.</p>
<ol>
<li>We figured out that there’s no real difference between writing a function with notations like the following two:</li>
</ol>
<pre><code>f(P, r, t) = P(<span class="hljs-number">1</span>+rt)A = P(<span class="hljs-number">1</span>+rt)
</code></pre><ol start="2">
<li>We figured out that we can solve for one variable to give us the desired result. However, the more complex the equation is, the more complicated getting the solution is.</li>
</ol>
<p>We have two equations of very opposing difficulties to solve. I will introduce a third equation that will help to bridge the gap</p>
<pre><code>y = <span class="hljs-number">2</span>x^<span class="hljs-number">2</span>+<span class="hljs-number">3</span>x<span class="hljs-number">-5</span>, eqn(<span class="hljs-number">3</span>)
</code></pre><p>The equation above is a basic parabolic function. This is what the equation looks like when plotted.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*v1T8kOf8DVqnD-sH7oc3vQ.png" alt="Image" width="800" height="657" loading="lazy">
<em>Plot of 2x²+3x-5</em></p>
<p>Okay, now let’s think about how to solve this equation. Let’s say we want to solve for <code>x</code> so that <code>y = 0</code>:</p>
<pre><code>y = <span class="hljs-number">2</span>x^<span class="hljs-number">2</span>+<span class="hljs-number">3</span>x<span class="hljs-number">-5</span> =&gt; <span class="hljs-number">2</span>x^<span class="hljs-number">2</span>+<span class="hljs-number">3</span>x<span class="hljs-number">-5</span> = <span class="hljs-number">0</span>
</code></pre><pre><code>x = [<span class="hljs-number">-3</span> + sqrt(<span class="hljs-number">3</span>^<span class="hljs-number">2</span> - <span class="hljs-number">4</span>*<span class="hljs-number">2</span>*(<span class="hljs-number">-5</span>))] / (<span class="hljs-number">2</span>*<span class="hljs-number">2</span>),     [<span class="hljs-number">-3</span> - sqrt(<span class="hljs-number">3</span>^<span class="hljs-number">2</span> - <span class="hljs-number">4</span>*<span class="hljs-number">2</span>*(<span class="hljs-number">-5</span>))] / (<span class="hljs-number">2</span>*<span class="hljs-number">2</span>)]
</code></pre><pre><code>x = <span class="hljs-number">1</span>, <span class="hljs-number">-2.5</span>
</code></pre><p>If you are wondering where I got the equation for the solutions from, notice it’s just the classic solution to a quadratic equation.</p>
<pre><code>y = ax^<span class="hljs-number">2</span>+bx+c, where y = <span class="hljs-number">0</span> =&gt; ax^<span class="hljs-number">2</span>+bx+c = <span class="hljs-number">0</span>
</code></pre><pre><code>x = -b+sqrt(b^<span class="hljs-number">2</span><span class="hljs-number">-4</span>ac) / <span class="hljs-number">2</span>a, x = -b-sqrt(b^<span class="hljs-number">2</span><span class="hljs-number">-4</span>ac) / <span class="hljs-number">2</span>a
</code></pre><p><em>Note: If you want to find out how this solution was derived, take a look <a target="_blank" href="https://www.purplemath.com/modules/sqrquad2.htm#formula">here</a>.</em></p>
<p>Well, that’s one way to solve the equation. You could potentially write a parser that could accept any equation, check the coefficients, accurately separate them and then attempt to solve the equation. You could also use the wonderful <a target="_blank" href="https://algebra.js.org/#equations">algebra.js</a> library here, which does what I just described.</p>
<p>However, if you look at the graph, you will notice that you could have solved this graphically. The goal was to find the point on the curve where <code>y = 0</code></p>
<p>Well, look carefully and see where the curve crosses the X-axis. It crosses it at two points: <code>[1, -2.5]</code> There’s your solution!</p>
<p>Now, you’re probably thinking that’s all great, but I can’t exactly teach a computer to look at the graph, find the points where it crosses the X-axis and identify those points. Well, potentially you could, with some form of model trained for image recognition, but that’s another post. So, how do we find our way around this?</p>
<p>There are two methods we can use, and these are the ones I will be exploring in depth in this article.</p>
<p>They are called the <strong>Newton-Raphson method</strong> and the <strong>bisection method</strong>.</p>
<p>I’ll give you a brief overview of how each method works.</p>
<p><strong>TL;DR Version</strong></p>
<p>The Newton-Raphson method works by picking a random point and drawing a tangent line at that point. It then calculates a new <code>x</code> value which is closer to the root. If you keep repeating this, you will find the root.</p>
<p>The Bisection method works on the principle of finding the interval within which the root lies. Once the accurate interval lies, the solution is found by using an algorithm similar to the one used for binary search.</p>
<p>Let’s get into each one in more detail.</p>
<h3 id="heading-newton-raphson-method">Newton-Raphson Method</h3>
<p>Okay, let’s dig into the Newton-Raphson method. The Newton-Raphson method is based on three major ideas.</p>
<ol>
<li>The tangent to a curve at a specific point is a straight line</li>
<li>The tangent to a curve at a specific point is also the derivative of the curve at that point</li>
<li>The equation of a straight line, which is: <code>y = mx + c</code></li>
</ol>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*QDGdH6GRcih-TU189cHX2w.png" alt="Image" width="706" height="312" loading="lazy">
_Tangent To A Curve At A Point. Source: [https://brilliant.org/wiki/newton-raphson-method/](https://brilliant.org/wiki/newton-raphson-method/" rel="noopener" target="<em>blank" title=")</em></p>
<p>The image above is that of a random curve with a tangent drawn to it.</p>
<p>We’ve picked a random point <code>x_n</code> on the X-axis.</p>
<p><code>f(x_n)</code> is the equivalent of the point on the curve. i.e the y-intercept</p>
<p><code>f’(x_n)</code> is the tangent to the curve at the point f(x_n).</p>
<p><code>x_(n+1)</code> is the point where the tangent intercepts the X-axis.</p>
<p>Remember, we said we wanted to find the point where the curve crosses the X-axis, as this would give us our solution. Notice, the point <code>x_(n+1)</code> is a lot closer to the solution than <code>x_n</code> was, despite us picking <code>x_n</code> at random.</p>
<p>Well, what if we repeated the same process, except this time with <code>x_(n+1)</code> as our new point initial point? Well, presumably we would end up with a new <code>x</code> that is even closer to the solution.</p>
<p>So, how do we find the point <code>x_(n+1)</code>given the equation, the derivative and the original <code>x_n</code>?</p>
<p>Let’s go back to the equation of a straight line: <code>y = mx+c</code></p>
<p>We said that the tangent to a curve at a point is a straight line.</p>
<p>We also said that the y-intercept is equal to <code>f(x_n)</code></p>
<p>We know from calculus, that the derivative is equal to the slope.</p>
<p>Therefore, we get the following:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*7Uoj0Og0M-rM0BFrHMcmRw.png" alt="Image" width="219" height="23" loading="lazy">
<em>Equation of a line</em></p>
<p>Now, we need to find the root of this tangent line, so set <code>y = 0</code> and <code>x = x_(n+1)</code>, and solve for <code>x_(n+1)</code></p>
<p>This gives us the following:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*yoa_cFXA4ywq0yUGg6VJYw.png" alt="Image" width="157" height="38" loading="lazy">
_Source: [https://brilliant.org/wiki/newton-raphson-method/](https://brilliant.org/wiki/newton-raphson-method/" rel="noopener" target="<em>blank" title=")</em></p>
<p>Now, we have everything we need to solve for <code>x_(n+1)</code>.</p>
<p>This went way over my head the first time I saw all the equations, so let’s try it with an example to see how it works.</p>
<p>We’ll take eqn(2) and work through that. Let’s pick <code>x_n=3</code></p>
<pre><code>f(x) = <span class="hljs-number">2</span>x^<span class="hljs-number">2</span>+<span class="hljs-number">3</span>x<span class="hljs-number">-5</span>f<span class="hljs-string">'(x) = 4x+3f(3) = 18+9-5 = 22f'</span>(<span class="hljs-number">3</span>) = <span class="hljs-number">15</span>x_1 = <span class="hljs-number">3</span> - <span class="hljs-number">22</span>/<span class="hljs-number">15</span> = <span class="hljs-number">1.53</span>
</code></pre><pre><code>f(<span class="hljs-number">1.53</span>) = <span class="hljs-number">4.2718</span>f<span class="hljs-string">'(1.53) = 9.12x_2 = 1.53 - 4.2718/9.12 = 1.0616</span>
</code></pre><p>If you follow that all the way through, you should get a solution where <code>x=1</code> and as we know from the earlier graph, this is one of our solutions.</p>
<p>If you notice what we did above was just follow a series of steps in a certain order repeatedly, i.e. the very definition of an algorithm. Here is what the code looks like for the same.</p>
<p>The code snippet makes heavy use of the <a target="_blank" href="http://mathjs.org/">math.js library</a>. The main functions I am making use of are the math.derivative and the math.eval functions. Respectively, they calculate the derivative of an expression and evaluate an expression based on an object of key-value pairs.</p>
<p>The bit of the code snippet I want to draw your attention to is lines 14–16.</p>
<pre><code><span class="hljs-keyword">if</span> (<span class="hljs-built_in">Math</span>.abs(result - guess) &lt; <span class="hljs-built_in">Math</span>.exp(<span class="hljs-number">-15</span>)) {              <span class="hljs-keyword">return</span> result        }
</code></pre><p>What we’re doing here is defining the base condition to end our iteration. We’re saying that if the difference between <code>x_n</code> and <code>x_(n+1)</code> is less than <code>10^(-15)</code> return the result.</p>
<p>If you work through the prior exercise all the way through, you’ll arrive at a situation where each successive <code>x</code> value is almost identical to the prior <code>x</code> value, and this is how we know we have found a solution.</p>
<p>I have a nice little simulation built with d3.js in codepen showing you how this would run iteratively.</p>
<p>Just enter a value in the input box and hit submit and you can watch the algorithm run graphically.</p>
<p><em>Note: Please try a range of sensible inputs, I haven’t exactly built a robust system here.</em></p>
<h3 id="heading-bisection-method">Bisection Method</h3>
<p>Okay, so we figured out how the Newton-Raphson method works. Let’s tackle the bisection method next.</p>
<p>The bisection method is a lot easier to understand than the Newton-Raphson method. It’s based on a very simple mathematical property:</p>
<p><em>If a function f(x) is continuous on the interval [a, b] and the sign of f(a) !== f(b), then there is a value c in the range (a, b) where f(c) = 0. In other words, c is the root of the equation.</em></p>
<p>If that didn’t make sense to you, think about it purely numerically and then purely graphically.</p>
<p>Let’s say you have the following interval: [-7, 6]. Now if I ask you to count just the integers from -7 to 6, you would also count 0 at some point in that interval. That’s essentially what the property above says.</p>
<p>Let’s look at what this means graphically.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*zS0iP-KtUgAuJ0jLroL22A.png" alt="Image" width="800" height="595" loading="lazy">
_Image Source: [http://www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/07/bisection.html](http://www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/07/bisection.html" rel="noopener" target="<em>blank" title=")</em></p>
<p>The above function is a continuous line and it goes from negative to positive, which implies that it has to cross 0 at some point. Since it has to cross 0, that means the root lies in this interval.</p>
<p>Okay, this means that using the bisection method is a two-step process.</p>
<ol>
<li>Find the interval within which the root lies, if such an interval exists</li>
<li>Find the actual root within this interval</li>
</ol>
<p>Here’s the code for how you’d find the interval:</p>
<p>Again, I am making use of mathjs here, so you can look up the documentation for that.</p>
<p>The interesting bit of this algorithm is in lines 18–26, where I am making a check to see if either my function evaluation of the left interval or right interval has resulted in something that is <code>NaN</code> . I will explain why I included this code block when we explore how to solve eqn(2).</p>
<p>Once we have the interval within which the solution lies, we can turn our attention to actually finding the solution itself.</p>
<p>If you’ve ever tried to write a binary search algorithm on an array, the code snippet above should look very familiar to you. We are employing more or less the same approach here. Here are the steps involved.</p>
<ol>
<li>I start with my left and right intervals and find a mid-point</li>
<li>Check whether the solution lies to the left of the mid-point or to the right of the mid-point</li>
<li>If it lies to the left, set <code>right = mid</code> , else set <code>left = mid</code></li>
</ol>
<p>Eventually, the midpoint will be the root itself.</p>
<p>Here is a little simulation running through what is actually going on.</p>
<p><em>Note: I apologise for how ugly the simulation looks, unfortunately styling is not my forte. Again, sensible range of inputs, because otherwise its going take quite a while for the simulation to run.</em></p>
<p>In the pen above, enter a value, and the simulation will attempt to find an interval within which a potential root could exist. Once it has found an interval, it will start trying to find the root by using the algorithm we discussed immediately prior to this.</p>
<h3 id="heading-solving-complex-equations"><strong>Solving Complex Equations</strong></h3>
<p>Alright, we’ve explored two different methods of finding the roots of equations. Now, its time to explore the more complex eqn(2) we had and see which of these methods can solve that equation.</p>
<p>I’ll put the equation below so it’s clear</p>
<pre><code>f(x, y) = <span class="hljs-number">1550</span> - (<span class="hljs-number">4</span>*x/y * sinh(y/<span class="hljs-number">2</span> * <span class="hljs-number">1500</span> / (<span class="hljs-number">2</span>*x))), eqn(<span class="hljs-number">2</span>)
</code></pre><pre><code>Solve <span class="hljs-keyword">for</span> f(x, y) = <span class="hljs-number">0</span>, where y = <span class="hljs-number">0.022</span>
</code></pre><pre><code><span class="hljs-number">0</span> = <span class="hljs-number">1550</span> - (<span class="hljs-number">4</span>*x/<span class="hljs-number">0.022</span> * sinh(<span class="hljs-number">0.022</span>/<span class="hljs-number">2</span> * <span class="hljs-number">1500</span> / (<span class="hljs-number">2</span>*x)))
</code></pre><p>First, let’s visualize what this equation looks like. It’ll give us a much better intuition for why something might go wrong.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*56y9PGq5znTkICE_TfAJOw.png" alt="Image" width="800" height="666" loading="lazy">
<em>f(x) = 1550 — (4x/0.022 <em> sinh(0.022/2 </em> 1500 / (2x)))</em></p>
<p>The thing to note about this equation is that it tends to infinity as x tends to 0. This is going to pose a problem for the Newton-Raphson method because the Newton-Raphson solution tends to follow the path of the tangent, in which case it might quickly dissolve to infinity as a solution unless it managed to hit on the solution by chance.</p>
<p>Try running the above equation with the Newton-Raphson method and you’ll see what I mean. You will probably get a result of null.</p>
<p>The bisection method, on the other hand, will work quite nicely for this. It works well because we are taking very small incremental steps with a step size we have control over. Run the below codepen and you should see how nicely the bisection method works for most equations.</p>
<p>The code above is almost identical to the previous version we set up for the bisection method, baring a few differences. I set up a separate codepen so I could be spared the effort of having to allow a way to enter equations, which would require extensive checks and error handling. Also, this equation requires special boundaries for defining its data since it tends to infinity as x approaches 0. If you’re interested you can see what I mean if you have a look through the code.</p>
<p>Now, in the bisection method code I told you about this block of code here:</p>
<pre><code><span class="hljs-keyword">if</span> (<span class="hljs-built_in">Number</span>.isNaN(result_left)) {        left -= stepSize        scope_left[variable] = left        result_left = math.eval(eqn, scope_left)    } <span class="hljs-keyword">if</span> (<span class="hljs-built_in">Number</span>.isNaN(result_right)) {        right += stepSize        scope_right[variable] = right        result_right = math.eval(eqn, scope_right)}
</code></pre><p>So the reason I have this is to handle situations like those that arise for eqn(2). Because eqn(2) tends to infinity as x tends to 0, there could be a situation where the evaluation of the equation returns either <code>NaN</code> or <code>Infinity</code> . To avoid this situation, I simply shift the equation over by the step size repeatedly until I can get back to the domain of the function that lies in the real number range.</p>
<h3 id="heading-bisection-gt-newton-raphson"><strong>Bisection &gt; Newton-Raphs</strong>on?</h3>
<p>This brings me to an important point, why did Newton-Raphson fail for this equation? We know that since Newton-Raphson follows the tangent of the curve at different points, it can dissolve to infinity if the equation tends to infinity at any particular point. This highlights one of the shortcomings of the Newton-Raphson method.</p>
<ol>
<li>The Newton-Raphson method works well for a <strong><em>continuous</em></strong> function. If the function is discontinuous as in eqn(2) is, it will typically fail.</li>
<li>Newton-Raphson cannot account for multiple maxima and minima in a function.</li>
</ol>
<p>Take the following graph for example.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*GmEkZ9CzPRQdwVVLi8lhRw.png" alt="Image" width="590" height="360" loading="lazy">
_A function with multiple maxima and minima. Source: [https://brilliant.org/wiki/newton-raphson-method/](https://brilliant.org/wiki/newton-raphson-method/" rel="noopener" target="<em>blank" title=")</em></p>
<p>Pick a point at random between -0.19 and +0.19, and you should see that you will get a negative slope, which means the tangent to the curve at that point will intercept the X-axis at a point further away from the root, which goes against the principle of the Newton-Raphson method. This implies that Newton-Raphson will typically fail for cubic and higher order equations.</p>
<p>The Bisection Method should not have the same problem because it depends on finding an interval within which the solution has to lie, and curves like the above will not be an obstacle to that as long it is continuous in that domain.</p>
<p>If you compare the two in terms of Big(O) notation, it seems obvious that Newton-Raphson runs on fewer iterations than the Bisection method, simply because it converges much faster when you view it graphically. Ironically, if you run this with a timing process, it frequently turns out that, given the same starting point, the Bisection method runs faster than the Newton-Raphson method.</p>
<p>This is because the Newton-Raphson involves computing a derivative at every step, which turns out to be very computationally expensive. Incrementing and decrementing a number on the other is relatively computationally inexpensive.</p>
<p>If you want to run the same on your machine and check the results, check out the repo <a target="_blank" href="https://github.com/redixhumayun/root-finding">here</a>. You can clone that repo, run <code>npm install</code> and then <code>npm run start</code> on your machine, and you should see the results of running both the Newton-Raphson and Bisection method on an identical equation given the same initial guess.</p>
<h3 id="heading-conclusion"><strong>Conclusion</strong></h3>
<p>Okay, we’ve covered a lot here. But honestly, this is such a ridiculously vast topic that I’ve barely scratched the surface. Convergence of equations is a widely studied topic. Consider one of the most basic things we haven’t covered: finding multiple roots.</p>
<p>You can of course modify the algorithms provided in this article to achieve that.</p>
<p>Take the equation below, for example. It has 3 roots (3 points where it intercepts the X-axis, and you need to find all of these roots).</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*QSL-JQG8vggP1OHYw2xMKw.png" alt="Image" width="800" height="800" loading="lazy">
<em>Cubic equations have multiple roots</em></p>
<p>I’m going to post all my sources here, feel free to look through them.</p>
<p>_Note: If you have questions or comments about the article, don’t hesitate to reach out to me via comments on this article or on <a target="_blank" href="https://github.com/redixhumayun">GitHub</a> or <a target="_blank" href="https://twitter.com/zz_humayun">Twitter</a>._</p>
<ol>
<li><a target="_blank" href="https://brilliant.org/wiki/newton-raphson-method/">https://brilliant.org/wiki/newton-raphson-method/</a></li>
<li><a target="_blank" href="http://www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/07/bisection.html">http://www.mathcs.emory.edu/~cheung/Courses/170/Syllabus/07/bisection.html</a></li>
<li><a target="_blank" href="http://www.sosmath.com/calculus/diff/der07/der07.html">http://www.sosmath.com/calculus/diff/der07/der07.html</a></li>
<li><a target="_blank" href="https://www.youtube.com/channel/UCYO_jab_esuFRV4b17AJtAw">https://www.youtube.com/channel/UCYO_jab_esuFRV4b17AJtAw</a></li>
</ol>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
