How to Simplify Symbolic Calculations with SymPy (A+B)(A-B) = A^{2} - B^{2}

Hi all,

I have this integral with Mean Value Theorem to find value of c:

\frac{\int_{A}^{B} (ax+b) \ dx}{B-A} = f(c)

with
f(c) = ac+b

then I use this code:

using SymPy

x, a, b = symbols("x a b")

A, B = symbols("A B")

f = integrate(a*x+b, (x, A, B))

The answer is in square terms:

Capture d’écran_2022-12-15_14-01-12

The solution manual can be more simplified. Like this:
Capture d’écran_2022-12-15_13-57-49

Can Julia do this with SymPy so I will get the end result of

c = \frac{A+B}{2}

Yes. I will refer you to
https://docs.sympy.org/latest/tutorials/intro-tutorial/simplification.html

1 Like

It works very beautiful:

using SymPy

x, a, b = symbols("x a b")

A, B = symbols("A B")

g = integrate(a*x+b, (x, A, B))

d = simplify((g/(B-A) -b)/a)
println("c = ", d)

1 Like