Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Differential Equations #5

Open
salastro opened this issue May 6, 2022 · 1 comment
Open

Differential Equations #5

salastro opened this issue May 6, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@salastro
Copy link
Owner

salastro commented May 6, 2022

No description provided.

@salastro salastro added the enhancement New feature or request label May 6, 2022
@salastro
Copy link
Owner Author

salastro commented May 7, 2022

Probably won't do it, the code does not work.

diff --git a/doc.py b/doc.py
index daa7e76..374dc0d 100644
--- a/doc.py
+++ b/doc.py
@@ -1,5 +1,6 @@
+from __future__ import division
 from sympy import cos, exp, integrate, sqrt, diff, limit, Limit, oo, \
-    simplify, factor, trigsimp
+    simplify, factor, trigsimp, Derivative, dsolve, Function, symbols, Eq
 # from sympy.integrals.manualintegrate import manualintegrate, integral_steps
 from sympy.integrals.risch import NonElementaryIntegral
 from sympy.abc import x
@@ -55,6 +56,16 @@ class MathDoc(Document):
             agn.append(r'=')
             agn.append(latex(solution))
 
+    def ODE(self, equation):
+        solution = dsolve(equation, y)
+        print(equation)
+        print(solution)
+        with self.create(Alignat(numbering=True, escape=False)) as agn:
+            agn.append(latex(equation))
+            agn.append(r'=0')
+            agn.append(r'\Rightarrow')
+            agn.append(latex(solution))
+
     def Lim(self, equation, a=0):
         solution = limit(equation, x, a)
         with self.create(Alignat(numbering=True, escape=False)) as agn:
@@ -90,6 +101,11 @@ if __name__ == '__main__':
     doc = MathDoc()
     file_name = 'full'
 
+    y = Function("y")(x)
+    y_ = Derivative(y, x)
+    y__ = Derivative(y_, x)
+    y___ = Derivative(y__, x)
+
     doc.Heading(title='Integral Homework', author='SalahDin Rezk')
     doc.Inte(x/sqrt(1-3*x))
     doc.Inte(1/sqrt(1-3*x))
@@ -98,5 +114,7 @@ if __name__ == '__main__':
     doc.Diff(x**x, 2)
     doc.Diff(x**(1/x), 2)
     doc.Lim(1/x, oo)
+    from sympy import sin
+    doc.ODE(2*y_-y-4*sin(3*x))
 
     doc.generate_pdf(file_name, clean_tex=True)
diff --git a/main.py b/main.py
index 318f91c..b412c24 100644
--- a/main.py
+++ b/main.py
@@ -1,13 +1,10 @@
+from __future__ import division
 from doc import MathDoc
-from sympy import sin, cos, tan, exp, log, sqrt, sympify, pi, oo, \
-    symbols, asin, acos, atan  # common math
-from sympy import Function
+from sympy import sin, cos, tan, exp, log, ln, sqrt, sympify, pi, oo, \
+    symbols, asin, acos, atan, cot, csc, sec  # common math
+from sympy import Function, Derivative, Eq, dsolve
 from gui import QtWidgets, Ui_MainWindow  # gui
 
-# common symbols
-x, y, z, t = symbols('x y z t')
-f, g, h = symbols('f g h', cls=Function)
-
 
 if __name__ == "__main__":
     # Setup the ui.
@@ -17,6 +14,14 @@ if __name__ == "__main__":
     ui = Ui_MainWindow()  # Create the ui.
     ui.setupUi(MainWindow)  # Setup the ui.
 
+    # common symbols
+    from sympy.abc import x
+    y = Function("y")
+    y_ = Derivative(y, x, x)
+    y__ = Derivative(y_, x, x)
+    y___ = Derivative(y__, x, x)
+    # ! ValueError: -y + y_ is not a solvable differential equation in y(x)
+
     # Setup the document and buttons.
     math_doc = MathDoc()  # The document.
     # math_doc.GenPdf(ui.fileTxt.toPlainText(), ui.titleTxt.toPlainText(),
@@ -28,6 +33,8 @@ if __name__ == "__main__":
     ui.limBt.clicked.connect(lambda: math_doc.Lim(
         sympify(ui.expTxt.toPlainText().split(',')[0]),
         sympify(ui.expTxt.toPlainText().split(',')[1])))  # Limit button.
+    ui.odeBt.clicked.connect(lambda: math_doc.ODE(
+        sympify(ui.expTxt.toPlainText()), y, y__, y___, y___))  # ODE button.
     ui.simpBt.clicked.connect(lambda: math_doc.Simp(
         sympify(ui.expTxt.toPlainText())))  # simplfiy button
     ui.factBt.clicked.connect(lambda: math_doc.Fact(
@@ -35,10 +42,10 @@ if __name__ == "__main__":
     ui.plotBt.clicked.connect(lambda: math_doc.Plot(
         (ui.expTxt.toPlainText())))  # The plot button.
     ui.genPdfBt.clicked.connect(lambda: math_doc.GenPdf(ui.fileTxt.toPlainText(
-    ), ui.titleTxt.toPlainText(), ui.authorTxt.toPlainText(), clean_tex=True))
+        ), ui.titleTxt.toPlainText(), ui.authorTxt.toPlainText(), clean_tex=True))
     # The generate pdf button.
     ui.genLatexBt.clicked.connect(lambda: math_doc.GenTex(ui.fileTxt.toPlainText(
-    ), ui.titleTxt.toPlainText(), ui.authorTxt.toPlainText()))
+        ), ui.titleTxt.toPlainText(), ui.authorTxt.toPlainText()))
     # The generate tex button.
 
     MainWindow.show()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant