All problems
Scalar Line Integral on a Segment
Problem
The scalar line integral of f(x, y) = alpha*x + beta*y + gamma along the straight segment from P to Q integrates f with respect to arc length.
Because f is linear along the segment, the integral equals length(P, Q) * (f(P) + f(Q)) / 2. Given the coefficients and the endpoints as [x, y] pairs, return the integral.
Hint
The trapezoid rule is exact when the integrand is linear in the parameter.
Test cases
case 1
in: [1,0,0,[0,0],[3,4]]
expected: 7.5
case 2
in: [0,0,1,[0,0],[3,4]]
expected: 5
case 3
in: [1,1,0,[0,0],[1,1]]
expected: 1.4142135623730951
case 4
in: [2,-1,3,[1,1],[1,1]]
expected: 0
Starter codePython
def scalar_line_integral(alpha, beta, gamma, p, q):
# Your code here
pass4 test cases · run your code against them in the editor