integral

Why can't Mathematica solve this definite integral?

让人想犯罪 __ 提交于 2019-12-04 20:11:45
问题 When I try to calculate the following integral in Mathematica 8, I get this strange result: In[1]:= Integrate[y/((1 + x^2 + y^2)^(3/2)), {y, 0, 1}] Maple 14 can solve this one easily: Why is Mathematica giving me a different result? 回答1: Try this r = Integrate[y/((1 + x^2 + y^2)^(3/2)), {y, 0, 1}] r = Assuming[Element[x, Reals], Simplify[r]]; Together[r] which gives (-Sqrt[1+x^2]+Sqrt[2+x^2])/(Sqrt[1+x^2] Sqrt[2+x^2]) Which is the same as Maple's : 来源: https://stackoverflow.com/questions

Computing integral of a line plot in R

前提是你 提交于 2019-12-04 15:03:57
I have two positive-valued vectors x,y of the same length in R. Using plot(x, y, "l",...), gives me a continuous line plot in 2 dimensions out of my finite vectors x and y. Is there a way to compute a definite integral over some range of this line plot in R? edit1: I've looked into the integrate function in R. I'm not sure however how to make a function out of two vectors to pass to it, as my vectors are both finite. edit2: For some more background, The length of x and y ~ 10,000. I've written a function to find periods, [xi, xj], of abnormalities in the data I'm observing. For each of these

Why can't Mathematica solve this definite integral?

北战南征 提交于 2019-12-03 12:43:39
When I try to calculate the following integral in Mathematica 8, I get this strange result: In[1]:= Integrate[y/((1 + x^2 + y^2)^(3/2)), {y, 0, 1}] Maple 14 can solve this one easily: Why is Mathematica giving me a different result? Try this r = Integrate[y/((1 + x^2 + y^2)^(3/2)), {y, 0, 1}] r = Assuming[Element[x, Reals], Simplify[r]]; Together[r] which gives (-Sqrt[1+x^2]+Sqrt[2+x^2])/(Sqrt[1+x^2] Sqrt[2+x^2]) Which is the same as Maple's : 来源: https://stackoverflow.com/questions/8692674/why-cant-mathematica-solve-this-definite-integral

Best way to write a Python function that integrates a gaussian?

痴心易碎 提交于 2019-12-03 09:59:39
问题 In attempting to use scipy's quad method to integrate a gaussian (lets say there's a gaussian method named gauss), I was having problems passing needed parameters to gauss and leaving quad to do the integration over the correct variable. Does anyone have a good example of how to use quad w/ a multidimensional function? But this led me to a more grand question about the best way to integrate a gaussian in general. I didn't find a gaussian integrate in scipy (to my surprise). My plan was to

Fitting data with integral function

懵懂的女人 提交于 2019-12-03 09:23:12
问题 When using curve_fit from scipy.optimize to fit a some data in python, one first defines the fitting function (e.g. a 2nd order polynomial) as follows: def f(x, a, b): return a*x**2+b*x And then proceeds with the fitting popt, pcov = curve_fit(f,x,y) But the question is now, how does one go about defining the function in point 1. if the function contains an integral (or a discrete sum), e.g.: The experimental data is still given for x and f(x), so point 2. would be similar I imagine once I

Fitting data with integral function

情到浓时终转凉″ 提交于 2019-12-03 02:36:12
When using curve_fit from scipy.optimize to fit a some data in python, one first defines the fitting function (e.g. a 2nd order polynomial) as follows: def f(x, a, b): return a*x**2+b*x And then proceeds with the fitting popt, pcov = curve_fit(f,x,y) But the question is now, how does one go about defining the function in point 1. if the function contains an integral (or a discrete sum), e.g.: The experimental data is still given for x and f(x), so point 2. would be similar I imagine once I can define f(x) in python. By the way I forgot to say that it is assumed that g(t) has a well known form

Best way to write a Python function that integrates a gaussian?

痞子三分冷 提交于 2019-12-03 00:32:08
In attempting to use scipy's quad method to integrate a gaussian (lets say there's a gaussian method named gauss), I was having problems passing needed parameters to gauss and leaving quad to do the integration over the correct variable. Does anyone have a good example of how to use quad w/ a multidimensional function? But this led me to a more grand question about the best way to integrate a gaussian in general. I didn't find a gaussian integrate in scipy (to my surprise). My plan was to write a simple gaussian function and pass it to quad (or maybe now a fixed width integrator). What would

Divergent Integral in R is solvable in Wolfram

江枫思渺然 提交于 2019-12-02 08:44:22
I know that I asked the same question before, but as I am pretty new here the question was asked poorly and not reproducible. Therefore I try to do it better here. (If I only edit the old one probably nobody will read it) I have this double integral that I would like to integrate: Here is a picture ff<-function(g,t) exp((16)*g)*exp(-8*t-(-t-0.01458757)^2/(0.0001126501)) integrate(Vectorize(function(t) integrate(function(g) ff(g,t), -2.5,0)$value), -2, 2) Running this in R gives me the error: the integral is probably divergent When I try to run the sam function in Wolfram it gives me a proper

Why is the eval class giving me a casting error from int to double?

泄露秘密 提交于 2019-12-02 06:24:54
I am trying to make a method that takes a string formula, and solves the integral of that formula by doing a Riemann's sum with very small intervals. I am using the ScriptEngine and ScriptEngineManager classes to evaluate the function (with the eval() method). For some reason, I am getting this error: Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Double at sum.integral(sum.java:31) at sum.main(sum.java:13) import java.beans.Expression; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script

Numerical Triple Integration in R

吃可爱长大的小学妹 提交于 2019-12-01 23:04:08
Is it possible to do triple integration in R without using the cubature package? based on the answer in this post InnerFunc = function(x) { x + 0.805 } InnerIntegral = function(y) { sapply(y, function(z) { integrate(InnerFunc, 15, z)$value }) } integrate(InnerIntegral , 15, 50) 16826.4 with absolute error < 1.9e-10 For example, to code this triple integral : I tried InnerMostFunc = function(v) { v + y^2 } InnerMostIntegral = function(w) { sapply(w, function(x) { integrate(InnerMostFunc, 1, 2)$value }) } InnerIntegral = function(y) { sapply(y, function(z){integrate(InnerMostIntegral, 1, 2)