All problems
Exact ODE Potential
Problem
The differential M(x, y) dx + N(x, y) dy = 0 with M = a*x + b*y and N = c*x + d*y is exact exactly when b == c.
When it is exact, return the potential phi(x, y) = 0.5*a*x^2 + b*x*y + 0.5*d*y^2 with phi(0, 0) = 0. Otherwise return None.
Hint
Exactness requires the cross partials to match: dM/dy = dN/dx.
Test cases
case 1
in: [1,1,1,1,2,3]
expected: 12.5
case 2
in: [2,-3,-3,4,1,1]
expected: 0
case 3
in: [1,2,3,4,1,1]
expected: null
case 4
in: [0,0,0,0,5,5]
expected: 0
Starter codePython
def exact_ode_potential(a, b, c, d, x, y):
# Return None when the equation is not exact
# Your code here
pass4 test cases · run your code against them in the editor