Skip to content
DeepForgeby svx
All problems
EasyCalculusca-011

Average Value of a Function

Problem

Compute the average value of the polynomial f(x) = sum(coeffs[i] * x^i) on [a, b]:

avg = (1 / (b - a)) * integral of f from a to b

Integrate term by term using the power rule. Assume a != b.

Hint

The antiderivative term for c * x^i is c * x^(i+1) / (i+1).

Test cases

case 1
in: [[0,0,3],0,2]
expected: 4
case 2
in: [[1,2,1],0,1]
expected: 2.3333333333333335
case 3
in: [[4],1,5]
expected: 4
case 4
in: [[0,1],-1,1]
expected: 0
case 5
in: [[0,0,0,1],0,2]
expected: 2
Starter codePython
def average_value(coeffs, a, b):
    # Your code here
    pass

5 test cases · run your code against them in the editor