Questions tagged [numerical-integration]

Algorithms that integrate functions over one or more dimensions using approximation techniques, instead of exact, closed-form solutions using symbolic algebra and calculus. Includes concepts like adaptive quadrature, Monte-Carlo methods, finite element analysis, Markov chains.

Methods of numerical integration include:

769 questions
-1
votes
1 answer

Double Numerical Integration Error

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…
R Thompson
  • 353
  • 3
  • 15
-1
votes
1 answer

The integral is probably divergent

fun1 = function(y,mu=mu0,lsig=lsig0) { res = 1/(exp(-y)+1)^2 * 1/sqrt(2*pi)/exp(lsig) * exp(-(y-mu)^2/2/exp(lsig)^2) return(res) } fun4 = function(para=c(mu1,lsig1)) { mu1 = para[1] lsig1 = para[2] res = n1 *…
user67275
  • 1
  • 9
  • 38
  • 64
-1
votes
2 answers

Numerical integration: Make template function take either only the function name or the function called with two arguments

I'm new to C++ and I'm trying to write/edit a code that integrates numerically a function using the trapezoidal rule. This works fine as long as I only pass the name of the function. However, if I pass the function with two parameters this obviously…
Ethunxxx
  • 1,229
  • 4
  • 16
  • 34
-1
votes
1 answer

Matlab: Export changing variable with ode45 to solve ODE in separate function file

I have rather lengthy system of equations saved in a function file, system3. I need one of the parameters in this system to change dependant on time. I have created a second function, calculate_a1, that produces a vector of the parameter a1 at each…
Avg
  • 21
  • 5
-1
votes
2 answers

ODEINT output to txt file instead of console

Is there a way to write the outputs of t and x of this example to a txt file instead of the console. Thanks! This is the example I copied from Odeint website. #include #include using namespace std; using…
hn.phuong
  • 835
  • 6
  • 15
  • 24
-1
votes
1 answer

Numerical Integration with Trapezoidal rule c++

I'm attempting to implement a Trapezoidal rule that utilizes previous function evaluations in order to avoid redundant computation. Two things: a) computed results are not converging and I'm a little unsure of why. I'll post of the mathematics…
Jimothy
  • 25
  • 7
-1
votes
1 answer

Integration of numerical data

I'm writing a test tomorrow and I'm contemplating doing everything on Matlab, to save time. Some questions require numerical integration of datapoints (points, not necessarily functions). E.g. C=[0 1 5 8 10 8 6 4 3 2.2 1.5 0.6 0]; I've used…
Mierzen
  • 566
  • 1
  • 5
  • 25
-2
votes
2 answers

Matlab trapz but splitting areas above and below the x-axis

I'm trying to find the area under a curve in the region both above the x-axis (from y = 0 to +inf) and below the x-axis, (y = 0 to -inf), separately. As far as I can figure out, I can use int = trapz(x,y) to get the area under the curve, but not as…
user2587726
  • 169
  • 2
  • 11
-2
votes
2 answers

How to compute the integral of a function which depends on the integral of another function

from scipy.integrate import quad from math import sqrt f = lambda x, a: a**2 * x # here a is a constant. F = lambda x, a: quad(f, 0, x, args=(a,))[0] rho = 5 I need to compute the integral of 1/sqrt(F(rho,a)-F(s,a)), s is from 0 (lower limit) to…
mathfun
  • 101
  • 7
-2
votes
2 answers

Calculate the area under each peak in a graph in python

I am trying to calculate the area under each peak in a graph that I plotted with a set of x and y co-ordinates, I don't have a function for (x,y), and so I haven't been able to find an appropriate method to do the same. the co-ordinates are { [10…
Amogha Varsha
  • 89
  • 1
  • 1
  • 8
-2
votes
2 answers

How to use exp() in integration function?

Here is a snippet of my code. from scipy.integrate import quad from numpy import exp, log, inf def f(x): return log(log(x))/(x*log(x**2)) val, err = quad(f, exp(), exp(2)) val I know the code is structured correctly but I cannot format the…
-2
votes
1 answer

I have a multiple variable function that I want to integrate in C (Used Trapezoidal Rule)

I have to integrate with respect to E, with it's lower and upper limits as the first value of my log10(E) column that I'm printing for each source and upper limit as the last value of the same column. My function is: fo E^-spectralindexexp(-tau1),…
-3
votes
1 answer

Euler method python

I have some problems with plot. Exatlct solution here is true, but eulerbmethod gives the same curve, but much lower import numpy as np import matplotlib.pyplot as plt # Define parameters f = lambda x, y: 2*x h = 0.1 x = np.arange(-10, 10, h) x0 =…
user19571137
-3
votes
1 answer

Matlab integration of circle circumference

It could be a simple question. I am trying to understand numerical integration in Matlab. For a unit circle, fun = @(x) sqrt(cosd(x).^2+sind(x).^2); q = integral(fun,0,360); The answer is 360.0000, whereas I expect it to be 2*pi. Note that the…
SKPS
  • 5,433
  • 5
  • 29
  • 63
-3
votes
1 answer

is it possible to write a program that can find zeros of a certain function?

In Gauss-legendre integration we need to find zeros of the legendre function but i can't find a way to write code that enable me to do that? I understand there are list of "xi"s out there by which this function equals to zero but can we write…
1 2 3
51
52