Pl.legend()Įxample 13: System of non-linear first order differential equations. # print scipy.shape(y_exact), scipy.shape(y_approx) Y_approx = (dy_dt, y0, t) # solve using odeint T = scipy.linspace(0, 10, 1000) # create 1000 time points stating at t0=0 Exact versus approximated solution"""ĭef dy_dt(y, t=0): # specify the initial time point t0=0ĭef f_exact(t): #exact solution starting at y0=1 """ Numerical solution of ordinary differential equation. Plot the curves of the exact solution and the approximated solution obtained with the function odeint on the same graph. Solve the non-linear first order equation with boundary condition. X = (dx_dt, x0, t) # solve using odeintĮxample 12: Exact versus approximated solution. T = scipy.linspace(0, 6, 1000) # create 1000 time points stating at t0=0 """ Numerical solution of ordinary differential equation """ĭef dx_dt(x, t=0): # specify the initial time point t0=0 Solve the ordinary linear equation with initial condition x(0)= 2. 4 Ordinary differential equations: the function odeint #Integrate ordinary differential equations. Result, error = (lambda t, x: func(x,t), 0, scipy.Inf, lambda x: 1, lambda x: scipy.Inf)ġ. Result, error = (lambda y, x: f(x,y), 0, 1, lambda y: 1, lambda y: 2)Ĭompute the integral. > result, error = (y, 0, 4.5)Ĭompute the integral. > result, error = (y, 0, scipy.inf)Įxample 9: Suppose you wish to integrate the besselįunction jv(2.5, x) along the interval. > y = lambda x: math.exp(-0.5*x) # using the lambda form to define a (pointer to a) function > result, error = (func, 0.0, 2) #numerical solution and errorĢ.960594732333751e-14) # the error in negligible Here are the steps to find the numerical solution ( integrate.inf indicates infinite limits). The function provides a mean to integrate a function of one variable between two points. Gauss_quad #Integrate func(x) using Gaussian quadrature of order n. Tplquad #General purpose triple integration. Odeint #Integrate ordinary differential equations.ĭblquad #General purpose double integration. > dir(sp.integrate) # list the functions available 2 Numerical integration: the scipy.integrate module > print polint(1) - polint(0) # apply the integral boundaries to compute the value of the integralġ. > polint = pol.integ() # close form of the integral
![scipy integrate quad scipy integrate quad](https://i.stack.imgur.com/amb23.png)
![scipy integrate quad scipy integrate quad](https://img-blog.csdnimg.cn/20200801101517588.png)
![scipy integrate quad scipy integrate quad](https://fredrikj.net/blog/2017/11/new-rigorous-numerical-integration-in-arb/rump.png)
> pol = np.poly1d()**5 # obtain the numpy polynomial form for the integrant Integrate the following polynomial forn 0 to 1 using the numpy function pol.integ The integrate function provides several integration techniques including an ordinary differential equation The lambda form allows to create a function object.Įxample 6: Solve the system on non-linear equations Python offers an alternative way of defining a function using the lambda form. Starting at x 0 = 1 and x 1 = 1 using fsolve > x0 = (f, 0.3) # 0.3 is the starting pointĮxample 5: Find the solution of the system of non-linear equations To find a root of a set of non-linear equations, the scipy submodule optimize.fsolve is needed.Įxample 4: First find the roots of the single-variable non-linear equation