All problems
Line Integral on a Segment
Problem
Compute the line integral of the linear field F(x, y) = [a*x + b*y, c*x + d*y] along the straight segment from P = (x0, y0) to Q = (x1, y1).
Parameterize r(t) = P + t*(Q - P) for t in [0, 1]. Because F is linear, the integrand F(r(t)) · (Q - P) is linear in t, so the integral equals the average of its endpoint values.
Hint
The average of the integrand at the two endpoints is exact when the integrand is linear in t.
Test cases
case 1
in: [1,0,0,1,0,0,2,3]
expected: 6.5
case 2
in: [0,1,1,0,0,0,1,1]
expected: 1
case 3
in: [0,-1,1,0,0,0,1,0]
expected: 0
case 4
in: [1,0,0,0,1,1,4,5]
expected: 7.5
Starter codePython
def line_integral(a, b, c, d, x0, y0, x1, y1):
# Your code here
pass4 test cases · run your code against them in the editor