integration with sage

This commit is contained in:
Valentin Boettcher 2021-11-24 19:15:54 +01:00
parent e0b9321030
commit 43841c0517

View file

@ -191,3 +191,130 @@ a\right)}\right)} \gamma\right)} e^{\left(T \gamma\right)}}\]
\gamma\right)} t\right)} \sin\left(\delta t + \phi\right)
\sin\left(\omega t + b\right)\]
:END:
#+begin_src jupyter-python
var('t,s,r,l,u')
var('P_k,L_k,B_n,C_n,B_m,C_m,G_l,W_l,Gc_l,Wc_l', domain=CC)
#+end_src
#+RESULTS:
| P_k | L_k | B_n | C_n | B_m | C_m | G_l | W_l | Gc_l | Wc_l |
#+begin_src jupyter-python
α(t) = G_l * exp(-W_l * t)
α_conj(t) = Gc_l * exp(-Wc_l * t)
α_dot(t) = P_k * exp(-L_k * t)
B_1(t) = B_n * exp(-C_n * t)
B_2(t) = B_m * exp(-C_m * t)
α_conj
#+end_src
#+RESULTS:
: t |--> Gc_l*e^(-Wc_l*t)
#+begin_src jupyter-python
inner = integrate(B_1(t-r-u) * α(u), u, 0, t-r) + integrate(B_1(t-r+u) * α_conj(u), u, 0, r)
inner
#+end_src
#+RESULTS:
: -B_n*G_l*(e^(C_n*r - C_n*t)/(C_n - W_l) - e^(W_l*r - W_l*t)/(C_n - W_l)) + B_n*Gc_l*(e^(C_n*r - C_n*t)/(C_n + Wc_l) - e^(-Wc_l*r - C_n*t)/(C_n + Wc_l))
#+begin_src jupyter-python
assume(C_n/L_k != -1)
assume(W_l/L_k != -1)
assume(-Wc_l/L_k != -1)
assume(-Wc_l/L_k != -1)
assume(L_k/(L_k+C_m) != -1)
#+end_src
#+RESULTS:
#+begin_src jupyter-python
whole = (B_2(s-r) * α_dot(t-s) * inner).integrate(r, 0, s).simplify_full()
#+end_src
#+RESULTS:
#+begin_src jupyter-python :results scalar
%display plain
integ = whole.integrate(s, 0, t, algorithm='giac')
#+end_src
#+RESULTS:
#+begin_src jupyter-python :results scalar
import sympy
from sympy.utilities.codegen import codegen
integ_s = sympy.sympify(integ)
result = codegen(("conv_part", integ_s), "F95")
for name, contents in result:
with open(name, 'w') as f:
f.write(contents)
#+end_src
#+RESULTS:
#+begin_src jupyter-python
%display latex
(B_2(s-r) * α_dot(t-s)).integrate(s, r, t)
#+end_src
#+RESULTS:
:RESULTS:
\[\newcommand{\Bold}[1]{\mathbf{#1}}-B_{m} P_{k}
{\left(\frac{e^{\left(C_{m} r - C_{m} t\right)}}{C_{m} - L_{k}} -
\frac{e^{\left(L_{k} r - L_{k} t\right)}}{C_{m} - L_{k}}\right)}\]
:END:
#+begin_src jupyter-python
%display latex
(B_1(t-r-u) * α(u)).integrate(u, 0, t-r)
#+end_src
#+RESULTS:
:RESULTS:
\[\newcommand{\Bold}[1]{\mathbf{#1}}-B_{n} G_{l}
{\left(\frac{e^{\left(C_{n} r - C_{n} t\right)}}{C_{n} - W_{l}} -
\frac{e^{\left(W_{l} r - W_{l} t\right)}}{C_{n} - W_{l}}\right)}\]
:END:
#+begin_src jupyter-python
%display latex
(B_1(t-r+u) * α_conj(u)).integrate(u, 0, r)
#+end_src
#+RESULTS:
:RESULTS:
\[\newcommand{\Bold}[1]{\mathbf{#1}}B_{n} \mathit{Gc}_{l}
{\left(\frac{e^{\left(C_{n} r - C_{n} t\right)}}{C_{n} +
\mathit{Wc}_{l}} - \frac{e^{\left(-\mathit{Wc}_{l} r - C_{n}
t\right)}}{C_{n} + \mathit{Wc}_{l}}\right)}\]
:END:
#+begin_src jupyter-python
assume(C_n/C_m != -1)
assume(L_k/C_m+C_n/C_m-1 != -1)
#+end_src
#+RESULTS:
#+begin_src jupyter-python
((exp(-C_m * r)) * (exp(-W_l * r))).integrate(r, 0, t)
#+end_src
#+RESULTS:
:RESULTS:
\[\newcommand{\Bold}[1]{\mathbf{#1}}-\frac{e^{\left(-C_{m} t - W_{l}
t\right)}}{C_{m} + W_{l}} + \frac{1}{C_{m} + W_{l}}\]
:END:
#+begin_src jupyter-python
((exp(-L_k * (t-r))) * (exp(-Wc_l*r)*exp(-C_n*t))).integrate(r, 0, t)
#+end_src
#+RESULTS: