|
|
import sympy as sp |
|
|
|
|
|
|
|
|
def test_corrected_examples(): |
|
|
x, y = sp.symbols('x y') |
|
|
|
|
|
print("Testing Corrected Numerical Examples:") |
|
|
print("=" * 50) |
|
|
|
|
|
|
|
|
print("Case 1: F(x,y) = [2, 3y²]") |
|
|
Vx = 2 |
|
|
Vy = 3 * y**2 |
|
|
|
|
|
|
|
|
phi_manual = 2*x + y**3 |
|
|
|
|
|
|
|
|
print(f"∂φ/∂x = {sp.diff(phi_manual, x)} = Vx? {sp.diff(phi_manual, x) == Vx}") |
|
|
print(f"∂φ/∂y = {sp.diff(phi_manual, y)} = Vy? {sp.diff(phi_manual, y) == Vy}") |
|
|
print() |
|
|
|
|
|
|
|
|
print("Case 2: F(x,y) = [2x + 3y + 1, 3x + 4y + 2]") |
|
|
Vx2 = 2*x + 3*y + 1 |
|
|
Vy2 = 3*x + 4*y + 2 |
|
|
|
|
|
|
|
|
print(f"Gradient condition: ∂P/∂y = {sp.diff(Vx2, y)}, ∂Q/∂x = {sp.diff(Vy2, x)}") |
|
|
print(f"Field is gradient? {sp.diff(Vx2, y) == sp.diff(Vy2, x)}") |
|
|
|
|
|
|
|
|
phi_x = sp.integrate(Vx2, x) |
|
|
remaining = Vy2 - sp.diff(phi_x, y) |
|
|
phi_y = sp.integrate(remaining, y) |
|
|
phi_calculated = phi_x + phi_y |
|
|
|
|
|
print(f"Calculated potential: φ = {phi_calculated}") |
|
|
print(f"∂φ/∂x = {sp.diff(phi_calculated, x)} = Vx? {sp.diff(phi_calculated, x) == Vx2}") |
|
|
print(f"∂φ/∂y = {sp.diff(phi_calculated, y)} = Vy? {sp.diff(phi_calculated, y) == Vy2}") |
|
|
|
|
|
|
|
|
test_corrected_examples() |