Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

evaluate polynomial

<script>
// Javascript program for implementation 
// of Horner Method for Polynomial
// Evaluation.

// returns value of poly[0]x(n-1) + 
// poly[1]x(n-2) + .. + poly[n-1]
function horner(poly, n, x)
{

    // Initialize result
    let result = poly[0]; 

    // Evaluate value of polynomial
    // using Horner's method
    for (let i = 1; i < n; i++)
        result = result * 
                  x + poly[i];

    return result;
}

// Driver Code

// Let us evaluate value of
// 2x3 - 6x2 + 2x - 1 for x = 3
let poly = new Array(2, -6, 2, -1);
let x = 3;
let n = poly.length

document.write("Value of polynomial is " +
         horner(poly, n, x));

// This code is contributed by _saurabh_jaiswal.
</script>
Comment

PREVIOUS NEXT
Code Example
Javascript :: how we can use pagination in angular material and spring boot 
Javascript :: index javascript array 
Javascript :: createSearchParams 
Javascript :: The app structure generator Express 
Javascript :: Uncaught TypeError: $(...).steps is not a function 
Javascript :: javascript add unique values to array 
Javascript :: template.json replacing text in files 
Javascript :: lement.style { } 
Javascript :: how to hide all tabs in windows 10 
Javascript :: alert(document.cookie); 
Javascript :: Node-Red: 2Outputs 
Javascript :: key html 
Javascript :: Nodemailer Reuseable Code 1 
Javascript :: &lt;Link&gt; react import 
Javascript :: how to merge data rn 
Javascript :: how to add class to only one selected row then remove it after selecting it again 
Javascript :: form needs 2 clicks to submit react 
Javascript :: request body goes undefined in nodejs mongodb 
Javascript :: acc&egrave;der data-id javascript 
Javascript :: Yup validation for objects and object shape 
Javascript :: javascript condition based on table cell value 
Javascript :: how to use sort with tiebreak in js 
Javascript :: alertify.js styled success messae 
Javascript :: SuiteScript https.post a pdf file 
Javascript :: Block Alignment Toolbar Using ESNext in Wordpress 
Javascript :: set style javascript and cancel it to use default 
Javascript :: react-navigation: Detect when screen, tabbar is activated / appear / focus / blur 
Javascript :: angular mat-calendar send to form 
Javascript :: shipengine connect 
Javascript :: python to javascript converter 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =