numerical-integration

Absolute error of ODE45 and Runge-Kutta methods compared with analytical solution

夙愿已清 提交于 2019-12-28 02:53:05
问题 I would appreciate if someone can help with the following issue. I have the following ODE: dr/dt = 4*exp(0.8*t) - 0.5*r ,r(0)=2, t[0,1] (1) I have solved (1) in two different ways. By means of the Runge-Kutta method (4th order) and by means of ode45 in Matlab. I have compared the both results with the analytic solution, which is given by: r(t) = 4/1.3 (exp(0.8*t) - exp(-0.5*t)) + 2*exp(-0.5*t) When I plot the absolute error of each method with respect to the exact solution, I get the

Double Numerical Integration Error

江枫思渺然 提交于 2019-12-25 18:42:52
问题 In the script below, in the for loop for calculating the double integrations, I keep receiving an error, and I'm unsure why: Error using * Inner matrix dimensions must agree. Error in @(t,p)-sin(t)*(G(:,1)*cos(p)+H(:,1)*sin(p)) Error in @(t,p)B{k}(t,p).*A{k}(t,p).*(V(t)-Veq).*sin(t) Error in integral2Calc>integral2t/tensor (line 228) Z = FUN(X,Y); NFE = NFE + 1; Error in integral2Calc>integral2t (line 55) [Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT); Error in integral2Calc (line 9) [q,errbnd

numerical integration python

爱⌒轻易说出口 提交于 2019-12-25 09:14:04
问题 I need to reduce the running time for quad() in python (I am integrating some thousands integrals). I found a similar question in here where they suggested to do several integrations and add the partial values. However that does not improve performance. Any thoughts? here is a simple example: import numpy as np from scipy.integrate import quad from scipy.stats import norm import time funcB = lambda x: norm.pdf(x,0,1) start = time.time() good_missclasified,_ = quad(funcB, 0,3.3333) stop = time

Standard Normal Quantile Function Integration in R

为君一笑 提交于 2019-12-24 04:25:11
问题 I need to compute a division of integrals, where the function q_alpha(z) is the quantile function of a standard normal distribution. I got a question regarding the denominator. As the normal standard distribution has Homoscedasticity, it is simmetric, continuous, etc.The integration of the denominator term its simple? I just need to elevated to the square each quantile of this function and proceed to the calculation? Right? This is my code in R: library(Bolstad) thau=1:99/100 z.standard

Write a function with NumPy to calculate integral with a specific tolerance

六月ゝ 毕业季﹏ 提交于 2019-12-24 03:31:21
问题 I want to write a custom function to integrate an expression (python or lambda function) numerically with a specific tolerance. I know with scipy.integrate.quad one can simply change the epsabs but I want to write the function myself using numpy. From this blogpost I know the function: def integrate(f, a, b, N): x = np.linspace(a+(b-a)/(2*N), b-(b-a)/(2*N), N) fx = f(x) area = np.sum(fx)*(b-a)/N return area gives me the numerical integration with N segments. How can I write another function

Tanh-sinh quadrature numerical integration method converging to wrong value

折月煮酒 提交于 2019-12-24 03:23:15
问题 I'm trying to write a Python program to use Tanh-sinh quadrature to compute the value of: but although the program converges to a sensible value with no errors in every case, it's not converging to the correct value (which is pi for this particular integral) and I can't find the problem. Instead of asking for a desired level of accuracy, the program asks for the number of function evaluations wanted, to make comparisons of convergence with simpler integration methods easier. The number of

matlab/octave random event ode45

一笑奈何 提交于 2019-12-24 02:08:11
问题 I have some troubles in understanding how to implement events in octave/matlab, in the resolution of differential equations. Consider for example this simple code to solve the differential equation y' = -y: function dy = odefun(t,y) dy = -y; endfunction options = odeset('RelTol',1e-4,'AbsTol',[1e-4]); [T,Y] = ode45(@odefun,[0 12],[1],options); Now I would like to introduce a random event. For example at some fixed time step I would like to randomly change the value of y and then continue the

How do I optimize numerical integration performance in Haskell (with example)

荒凉一梦 提交于 2019-12-23 15:26:04
问题 How do I optimize numerical integration routine (comparing to C)? What has been done to the moment: I replaced lists with unboxed vectors (obvious). I applied profiling techniques described in the book "Read World Haskell" http://book.realworldhaskell.org/read/profiling-and-optimization.html. I have inlined some trivial functions and inserted a lot of bangs everywhere. That gave about 10x speedup. I refactored the code (i.e. extracted iterator function). That gave 3x speedup. I tried to

The time-corrected Verlet numerical integration formula

我只是一个虾纸丫 提交于 2019-12-23 09:47:49
问题 There is a commonly used verlet-integration formula on the web by Johnathan Dummer, called Time-Corrected Verlet. However I've read several forum posts, that people get weird or unexpected results with it in certain conditions. Formula by Johnathan Dummer: x1 = x + (x – x0) * dt / dt0 + a * dt^2 There is also a stackoverflow answer, which states that Dummer's time-corrected formula is broken and the poster presents his own derivation as the correct one. Suggested correct formula by a

Matlab error in ode45 or fourth-order Runge-Kutta method to solve a system of coupled ODEs

三世轮回 提交于 2019-12-23 02:30:33
问题 I am a beginner at Matlab programming and with the Runge-Kutta method as well. I'm trying to solve a system of coupled ODEs using a 4th-order Runge-Kutta method for my project work. here is my problem... G = 1.4; g = 1.4; k = 0; z = 0; b = 0.166667; syms n; x2 = symfun(sym('x2(n)'),[n]); x1 = symfun(sym('x1(n)'),[n]); x3 = symfun(sym('x3(n)'),[n]); x4 = symfun(sym('x4(n)'),[n]); x5 = symfun(sym('x5(n)'),[n]); k1 = [x2 * x1 *n *(1 - z * x2)*(x1 - n) - 2 * x3 * n *(1 - z * x2) - x4^2 * x2 *(1 -