Integration, Symbolic and Numeric with Python

  Рет қаралды 83,855

APMonitor.com

APMonitor.com

Күн бұрын

Пікірлер: 53
@hamedjabarian1155
@hamedjabarian1155 4 жыл бұрын
Very helpful, articulated and practical examples just in very low time. Thanks
@gillespieQMA
@gillespieQMA 3 жыл бұрын
Thanks so much! Right to the point and practical!
@x9466x
@x9466x 5 жыл бұрын
Good video, just not what I was hoping for Just in case anyone was hoping this video would be about numeric integration in python, not importing scripts in python, here's an actual numeric code: # example function def func(x): y = 1 y = (x*x*x) - (2*(x*x)) + x - 3 return y # Integrate function def integrate(start,end,step): result = 1 index = start while(index
@apm
@apm 5 жыл бұрын
Thanks for adding your code!
@noobmaster-dm7tu
@noobmaster-dm7tu 2 жыл бұрын
thanks for this could you touch upon the difference between using quad and trapzd for integration?
@apm
@apm 2 жыл бұрын
Here is a good discussion on the trade-offs: scicomp.stackexchange.com/questions/34389/trapezoid-rule-vs-gaussian-quadrature-what-am-i-missing
@matrixate
@matrixate 6 жыл бұрын
Wow. My Python Professor needs to take lessons from you. Seriously. I've spent weeks studying from her and it's a bunch of guessing and anticipating and not clearly explained as this. My grant payers should get a refund.
@0284lourdes
@0284lourdes 5 жыл бұрын
Nice explanation, thanks
@AJ-et3vf
@AJ-et3vf 3 жыл бұрын
Very valuable. Thank you!
@johanmoens1825
@johanmoens1825 4 жыл бұрын
Top video! Is Matlab good in solving the more complex integrals?
@apm
@apm 4 жыл бұрын
For numeric solutions, most integration packages are similar (Python ODEINT versus MATLAB ode23, ode15s). You may also be interested in Python Gekko that handles high index DAEs and is built for large-scale and complex systems: gekko.readthedocs.io/en/latest/ and apmonitor.com/pdc/index.php/Main/PythonDifferentialEquations For analytic solutions, I'm not sure about Matlab but I have seen good results from Mathematica / Wolfram alpha. Here is more material: github.com/APMonitor/data_science/blob/master/11.%20Differential_Equations.ipynb
@kiranshakeel7651
@kiranshakeel7651 5 жыл бұрын
Hi thats a great video.Could you please tell if there are double integrals and dx, dy, how to deal with that in python?
@rrc
@rrc 5 жыл бұрын
You can integrate the integral.
@rookitchen
@rookitchen 3 жыл бұрын
I'm not a coder person. I need to output a bunch of anti derivatives as training data. I can't afford mathematica, so Im using jupytor with python 3 in my browser. I havent found a way to get wolfram alpha to output lists of antiderivatives like I want. My code only outputs one integral at a time. I thought maybe doing like a print(sp.integrate(x*sin(x**2),x), but I don't like its non-nice form. How can I get it to output a list of antideriviatives? My code: import sympy as sp from sympy import sin, cos, exp, log, simplify x = sp.Symbol('x') sp.integrate(x*sin(x**2),x) sp.integrate(x,x) The problem is that in the output, you can only see the last integral. So I try to do a print thing and then the outputs are no longer user friendly. import sympy as sp from sympy import sin, cos, exp, log, simplify x = sp.Symbol('x') print(sp.integrate(x*sin(x**2),x) ,sp.integrate(x,x)) I'll prolly figure it out before you get back to me, but figure Id put out a feeler.
@apm
@apm 3 жыл бұрын
Try using Jupyter notebook with init_printing() to have a cleaner output.
@rookitchen
@rookitchen 3 жыл бұрын
@@apm thank you!!!!
@sriharshakodati
@sriharshakodati 4 жыл бұрын
This is great. May I ask a query. When we use sympy for analytical solution for an integration, sometimes the output seem to be a piecewise datatype. May I know how to resolve this? Example: from sympy import * x=Symbol('x') alpha=Symbol('alpha') beta=Symbol('beta') W=Symbol('W') f1=(alpha-beta) result1=integrate(f1,(x,0,x)) f2=alpha*exp(-result1) result2=integrate(f2,(x,0,W)) M=1/(1-result2) print(M) Output: 1/(1 - Piecewise((alpha/(alpha - beta) - alpha*exp(-W*(alpha - beta))/(alpha - beta), Ne(alpha - beta, 0)), (W*alpha, True)))
@apm
@apm 4 жыл бұрын
Here is a tutorial on using Sympy to solve a differential equation: github.com/APMonitor/data_science/blob/master/11.%20Differential_Equations.ipynb
@sriharshakodati
@sriharshakodati 4 жыл бұрын
@@apm ops, I couldn't find about piecewise data type in there. Can you redirect me. Thanks!
@apm
@apm 4 жыл бұрын
@@sriharshakodati here is information on piecewise linear functions: apmonitor.com/wiki/index.php/Apps/PiecewiseLinear You may also want to look at cubic splines: apmonitor.com/wiki/index.php/Main/ObjectCspline
@sriharshakodati
@sriharshakodati 4 жыл бұрын
@@apm You are awesome! thanks!!
@sriharshakodati
@sriharshakodati 4 жыл бұрын
@@apm Thanks a lot!!!
@kuncheng3563
@kuncheng3563 4 жыл бұрын
It's pretty helpful, Thank you. Is it possible to integrate a function with a singularity and get a result consisting of the real and imaginary parts?
@apm
@apm 4 жыл бұрын
That is possible with Sympy
@ayanmitra3746
@ayanmitra3746 7 жыл бұрын
Hi great video, short and crisp. thanks. I have another question, if you would help will be great. If I have x & y column data, can you tell how can I integrate them [with y = int f(x) ]? thanks A M
@apm
@apm 7 жыл бұрын
Try the numpy trapz function: docs.scipy.org/doc/numpy/reference/generated/numpy.trapz.html
@Mahvendren
@Mahvendren 4 жыл бұрын
Can you integrate with Python to find volume?
@apm
@apm 4 жыл бұрын
Yes, Python odeint or quad are functions for integrating.
@francescodallevedove5018
@francescodallevedove5018 8 жыл бұрын
Hi nice video, but what about if I have a function to be integrated that has variable coefficient: f(w,t) = b(w)*cos(w*t). b(w) comes from a data base and let's say w(0,5,0.05) and we want F(t) = int f(w,t)) dw?
@apm
@apm 8 жыл бұрын
You can pass in arguments such as values or functions into scipy.integrate.quad. You can find additional help by issuing the command help(quad) after you import the module. Here is some sample code where I pass in both a function b(w) and a value for w: ### start code from scipy.integrate import quad import numpy as np def f(t,fcn,w): return fcn(w) * np.cos(w*t) # from database (such as b(w)=w^2) def b(w): return w**2 w = 0.05 F = quad(f,0,5,args=(b,w)) print(F[0]) ### end code You can see additional tutorials at apmonitor.com/che263
@francescodallevedove5018
@francescodallevedove5018 8 жыл бұрын
Thank you very much for your prompt response! It was very helpful!
@kedwards127
@kedwards127 5 жыл бұрын
Thank you so much this was extremely helpful!!
@hamzaa.8082
@hamzaa.8082 6 жыл бұрын
Thank you. Please magnify the screen a bit.
@apm
@apm 6 жыл бұрын
Thanks for the suggestion.
@ThomasJr
@ThomasJr 4 жыл бұрын
DEEPLY DISAPPOINTED WITH THIS PACKAGE. IT CAN'T INTEGRATE A FUNCTION THAT MATHEMATICA INTEGRATES BETTER AND FASTER. I TRIED IT THINKING IT WOULD BE A STEP UP FROM MATHEMATICA, BUT IT'S NOT SO. *Here the code.* q=3/2 n=2 def f(u): return u**q*(1-sp.cos(2*pi*n*(1-u))*sp.cot(pi*u)) exp = quad(f,0,1) *Am I doing something wrong?*
@apm
@apm 4 жыл бұрын
Is there a syntax error or is the numerical solution different?
@ThomasJr
@ThomasJr 4 жыл бұрын
@@apm Thanks for the answer. There is an error message perhaps about singularities in the region of integration, which Mathematica doesn't issue. Mathematica also seems much faster, for numeric integration. Python took a long time to calculate this integral with N=2, let alone if N had been 1000 (Mathematica calculates N=1000 fast, though it complains about accuracy, for N=100 it doesn't complain, but Python would probably never even finish). I don't understand why Alon Amit said Python is better than Mathematica for maths, I don't think this is the case at all based on this my first impression.
@apm
@apm 4 жыл бұрын
Mathematica is certainly a good computational engine. One of the appeals of Python is that breadth of open source packages. You can also call Mathematica from Python: mathematica.stackexchange.com/questions/4643/how-to-use-mathematica-functions-in-python-programs
@ThomasJr
@ThomasJr 4 жыл бұрын
@@apm Ok, thanks so much. There is an integral which is not converging exactly in Math-ica and I don't want to pay to run it in wolf alpha. That is that integral with N=1000. Do you think you would be able to calculate the above integral with N=1000 and q=1/2? I need to know the right value to confirm my theorem.
@ThomasJr
@ThomasJr 4 жыл бұрын
@@apm It doesn't give me any result cause it can't figure out the integral. And I know what result was expected, but this dumb package can't solve it. I guess there's probably a way to fix this, but I'm new to Python so I don't know.
@rohanarya1946
@rohanarya1946 7 жыл бұрын
Hi, Very well demonstrated. Thanks for the examples. I had a question with complex integrations. Is it impossible to derive symbolic expressions of integral like x/(1+0.000015x^2)? I keep getting the error "no convergence : try value of n 50. I tried changing these values too but no luck. Kindly, guide where I am wrong .
@apm
@apm 7 жыл бұрын
It looks like Sympy is not able to solve this one. This is what I used: import sympy as sym x = sym.Symbol('x') e = sym.integrate(x/(1+0.000015*(x**2)),x) print(e) I got a divide by zero error.
@apm
@apm 7 жыл бұрын
Wolfram Alpha was able to provide an analytical solution: www.wolframalpha.com/input/?i=integrate+x%2F(1%2B0.000015x%5E2)
@rohanarya1946
@rohanarya1946 7 жыл бұрын
APMonitor.com I was able to solve it after rounds of trial and error. It seems the coefficient of x^2 in the denominator was creating the issue. Just, take 0.00015 common and then try integrating. It gives the result. It's a strange way but it works :)
@allania7med113
@allania7med113 7 жыл бұрын
how i can make global assumption assume(x>3) so when i tape abs(x-3) i get x-3 and thxs
@apm
@apm 7 жыл бұрын
You could try Sympy to simplify your expression: stackoverflow.com/questions/27825581/sympy-simplify-relational-inequality-expression
@stasian11
@stasian11 6 жыл бұрын
liked it. thank u
@ThomasJr
@ThomasJr 4 жыл бұрын
may I borrow a bit of your beauty? lol
@stasian11
@stasian11 4 жыл бұрын
@@ThomasJr ahah sure man, subscribe my inst @redblaze.hsv and inherit 10% of my beauty =D
@ThomasJr
@ThomasJr 4 жыл бұрын
@@stasian11 haha, good one
@NZIT1
@NZIT1 6 жыл бұрын
Hi ApMonitor.com. Let's me start to give you thanks for the so wonderful explications regarding analytical and numerical way to solve integration using Python code. However I want just to mention one thing about the famous exercise to gave us to solve . (integral of exp^(-x)sin(3x)dx. For the analytical part you found zero as answer for that integration something I didn't understood, I tried it myself I got the answer which is different to zero. I was wondering why did we not get the same answer? Have you some reason for that? Thanks a lot .
@apm
@apm 6 жыл бұрын
That's hard for me to try to troubleshoot the difference without seeing your code. Did you get an answer close to zero? It could be machine roundoff. The answers maybe numerically similar but are off by a small number just because of the way the computers retain significant digits.
@yellowsmash332
@yellowsmash332 4 жыл бұрын
i am failing to apply integration help me f (x) = 20 e -20(x-12.5), limits (12.6 to infinity),(12.5 to 12.6) i want python code i tried d=12.6 sp.integrate(sp.exp(-20*(d-12.5)),y) output:0.135335283236614𝑦
Linear and Nonlinear Regression in Python
24:04
APMonitor.com
Рет қаралды 11 М.
Symbolic Manipulation in Python
28:18
APMonitor.com
Рет қаралды 63 М.
Арыстанның айқасы, Тәуіржанның шайқасы!
25:51
QosLike / ҚосЛайк / Косылайық
Рет қаралды 700 М.
UFC 310 : Рахмонов VS Мачадо Гэрри
05:00
Setanta Sports UFC
Рет қаралды 1,2 МЛН
BAYGUYSTAN | 1 СЕРИЯ | bayGUYS
36:55
bayGUYS
Рет қаралды 1,9 МЛН
Monte Carlo Integration In Python For Noobs
15:32
Andrew Dotson
Рет қаралды 155 М.
Derivatives, Symbolic and Numeric in Python
7:43
APMonitor.com
Рет қаралды 53 М.
Exact Areas and Definite Integral with Python
6:34
Jacob Koehler
Рет қаралды 22 М.
Python Symbolic and Numeric Solutions
16:15
APMonitor.com
Рет қаралды 16 М.
Netflix Removed React?
20:36
Theo - t3․gg
Рет қаралды 62 М.
Solving Systems Of Equations Using Sympy And Numpy (Python)
15:23
Andrew Dotson
Рет қаралды 78 М.
SymPy (Symbolic Expressions on Python) in one video | Python # 5
46:38
Python Integration, Interpolation, and Curve Fitting
15:25
ignite.byu.edu
Рет қаралды 58 М.
Арыстанның айқасы, Тәуіржанның шайқасы!
25:51
QosLike / ҚосЛайк / Косылайық
Рет қаралды 700 М.