Calculate an Integral in JavaScript – Programming Code Examples
JavaScript

Calculate an Integral in JavaScript1 min read

An integral method is used to calculate a shaped area. You can use the following javascript example to calculate the above integral.

JavaScript Code:

 

 

1 Comment

  • a very specific integral. might be better to accept them as an array indicating the order, so:
    [1,2,3,4,5]=5x^4+4x^3+3x^2+2x+1, then you would build it as:
    function integral(input,x)
    {
    var res=0;
    for(var i=0;i<input.length;i++)
    {
    power=i+1;
    res+=((input[i]*Math.pow(x,power))/power);
    }
    return res;
    }

    if one of the numbers was subtracted put in a negative so 2x^2-3x+1 would be [1,-3,2]

Leave a Comment