Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from sympy import symbols, integrate, diff, latex
|
3 |
+
|
4 |
+
# Define the Streamlit app
|
5 |
+
def main():
|
6 |
+
st.title("Integration by Parts - Step-by-Step Solver")
|
7 |
+
st.markdown(
|
8 |
+
"""
|
9 |
+
Integration by Parts formula:
|
10 |
+
\
|
11 |
+
\\int u \\cdot v' \\, dx = u \\cdot v - \\int v \\cdot u' \\, dx
|
12 |
+
\
|
13 |
+
"""
|
14 |
+
)
|
15 |
+
|
16 |
+
# Input section
|
17 |
+
st.header("Input Function")
|
18 |
+
function_input = st.text_input(
|
19 |
+
"Enter the integrand (e.g., x * exp(x) or ln(x)):", "x * exp(x)"
|
20 |
+
)
|
21 |
+
u_input = st.text_input(
|
22 |
+
"Choose 'u' (e.g., x for x * exp(x)):",
|
23 |
+
"x"
|
24 |
+
)
|
25 |
+
|
26 |
+
# Process inputs
|
27 |
+
if st.button("Solve"):
|
28 |
+
try:
|
29 |
+
x = symbols("x")
|
30 |
+
# Parse the integrand and chosen `u`
|
31 |
+
integrand = eval(function_input)
|
32 |
+
u = eval(u_input)
|
33 |
+
dv = integrand / u
|
34 |
+
|
35 |
+
# Compute derivatives and integrals
|
36 |
+
du = diff(u, x)
|
37 |
+
v = integrate(dv, x)
|
38 |
+
|
39 |
+
# Apply the formula
|
40 |
+
result = u * v - integrate(v * du, x)
|
41 |
+
|
42 |
+
# Display steps
|
43 |
+
st.subheader("Step-by-Step Solution")
|
44 |
+
st.latex(f"u = {latex(u)}, \\quad v' = {latex(dv)}")
|
45 |
+
st.latex(f"du = {latex(du)}, \\quad v = \\int {latex(dv)} \\, dx = {latex(v)}")
|
46 |
+
st.markdown("Substituting into the formula:")
|
47 |
+
st.latex(
|
48 |
+
f"\\int {latex(integrand)} \\, dx = {latex(u)} \\cdot {latex(v)} - \\int {latex(v)} \\cdot {latex(du)} \\, dx"
|
49 |
+
)
|
50 |
+
st.latex(f"= {latex(result)} + C")
|
51 |
+
|
52 |
+
# Final output
|
53 |
+
st.subheader("Final Answer")
|
54 |
+
st.latex(f"{latex(result)} + C")
|
55 |
+
|
56 |
+
except Exception as e:
|
57 |
+
st.error(f"An error occurred: {e}")
|
58 |
+
|
59 |
+
# Run the app
|
60 |
+
if __name__ == "__main__":
|
61 |
+
main()
|