integral

How do I fit a function that includes an integral with a variable limit?

淺唱寂寞╮ 提交于 2019-12-11 00:07:30
问题 I'm very new to Python (and also Stack Overflow so sorry if I'm not doing this right!). I'm trying to fit the following equation to some data in order to extract the cosmological parameters ΩM and ΩΛ: Equation to fit where Curly D equation In my equation, capital curly D=Ho*dl so the Ho has been cancelled out. I'm currently trying to use the ΩM+ΩΛ=1 form. I have the data for m(z) and z, and I know the curly M constant. This is the code I have at the moment: import numpy as np import scipy

Use the Gauss-Laguerre quadrature to approximate an integral in R

拥有回忆 提交于 2019-12-10 18:39:18
问题 I am using the Gauss-Laguerre quadrature to approximate the following integral I wrote the function in R int.gl<-function(x) { x^(-0.2)/(x+100)*exp(-100/x) } First, I used integrate() function to get the "true" value, which I double check with Wolfram Alpha integrate(int.gl, lower = 0, upper = Inf)$value [1] 1.627777 Then, I used glaguerre.quadrature() function rule<-glaguerre.quadrature.rules(64, alpha = 0, normalized = F)[[64]] glaguerre.quadrature(int.gl, lower = 0, upper = Inf, rule =

What does 'Conditional expressions can be only boolean, not integral.' mean?

不羁的心 提交于 2019-12-10 17:57:57
问题 What does 'Conditional expressions can be only boolean, not integral.' mean? I do not know Java and I know C++ deffenetly not enought to understend what it means.. Please help (found in http://www.javacoffeebreak.com/articles/thinkinginjava/comparingc++andjava.html in Comparing C++ and Java item 7 sub item 1) 回答1: Conditional expressions are used by the conditional and loop control structures to determine the control flow of a program. // conditional control structure if

How to calculate integral, numerically, in Rcpp

前提是你 提交于 2019-12-08 05:30:13
问题 I've searched for an hour for the methods doing numerical integration. I'm new to Rcpp and rewriting my old programs now. What I have done in R was: x=smpl.x(n,theta.true) joint=function(theta){# the joint dist for #all random variable d=c() for(i in 1:n){ d[i]=den(x[i],theta) } return(prod(d)*dbeta(theta,a,b)) } joint.vec=Vectorize(joint)##vectorize the function, as required when ##using integrate() margin=integrate(joint.vec,0,1)$value # the ##normalizeing constant at the donominator area

Nested integral within integral2 in matlab

守給你的承諾、 提交于 2019-12-08 05:00:46
问题 I'm attempting to take the double integral (using integral2) of a function that is defined by an integral. http://i.imgur.com/gIUsLSw.jpg Here is what I am currently attempting: t=linspace(0,1,50); fun_1= @(v) exp(.071*v) fun = @(x,y) exp(0.14*0.00607*integral(@(u)fun_1(u),0,x)).*exp(-(x-y).^2).*exp(0.14*0.00607*integral(@(u)fun_1(u),0,x)); for i=2:length(t) for j=i:length(t) A(i,j)=integral2(fun,t(i-1),t(i),t(j-1),t(j)); end end I'm receiving the error Error using integral (line 86) A and B

Calculate area of cross section for varying height

隐身守侯 提交于 2019-12-07 22:51:51
问题 I'm trying to figure out how to calculate the area of a river cross section. For the cross section I have the depth at every 25 cm over the 5 m wide river. x_profile <- seq(0, 500, 25) y_profile = c(50, 73, 64, 59, 60, 64, 82, 78, 79, 76, 72, 68, 63, 65, 62, 61, 56, 50, 44, 39, 25) If anyone have some suggestions of how this could be done in r it's highly appreciated. 回答1: We can use the sf package to create a polygon showing the cross-section and then calculate the area. Notice that to

Different integration results using Monte Carlo vs scipy.integrate.nquad

限于喜欢 提交于 2019-12-07 12:46:17
问题 The MWE below shows two ways of integrating the same 2D kernel density estimate, obtained for this data using the stats.gaussian_kde() function. The integration is performed for all (x, y) below the threshold point (x1, y1) , which defines the upper integration limits (lower integration limits are -infinity ; see MWE). The int1 function uses simple a Monte Carlo approach. The int2 function uses the scipy.integrate.nquad function. The issue is that int1 (ie: the Monte Carlo method) gives

How to compute integration of a function in apache commons math3 library?

ε祈祈猫儿з 提交于 2019-12-07 09:01:45
问题 I am trying to integrate a very simple function. integral(x.dx). Instead of getting an answer of 1, I am getting an answer as 0, or 0.5 when I include limits from 0 to 1. Is there something I misunderstand about the implementation of the integration in apache commons library? import org.apache.commons.math3.analysis.integration.*; import org.apache.commons.math3.analysis.polynomials.*; public static void main(String args[]) { SimpsonIntegrator simpson = new SimpsonIntegrator();

Integrate histogram in python?

*爱你&永不变心* 提交于 2019-12-07 07:25:09
问题 Is there a simple command in matplotlib that let's me take the integral of histogram over a certain range? If I plot a histogram with: fig = plt.hist(x, bins) Then, is there a command like fig.integral(bin1, bin2)? That will return the integral of the histogram from bin1 to bin2? 回答1: First, remember that the integral is just the total area underneath the curve. In the case of a histogram, the integral (in pseudo-python) is sum([bin_width[i] * bin_height[i] for i in bin_indexes_to_integrate])

How to calculate integral, numerically, in Rcpp

匆匆过客 提交于 2019-12-07 03:35:28
I've searched for an hour for the methods doing numerical integration. I'm new to Rcpp and rewriting my old programs now. What I have done in R was: x=smpl.x(n,theta.true) joint=function(theta){# the joint dist for #all random variable d=c() for(i in 1:n){ d[i]=den(x[i],theta) } return(prod(d)*dbeta(theta,a,b)) } joint.vec=Vectorize(joint)##vectorize the function, as required when ##using integrate() margin=integrate(joint.vec,0,1)$value # the ##normalizeing constant at the donominator area=integrate(joint.vec,0,theta.true)$value # the values at the ## numeritor The integrate() function in R