ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 01 Sep 2010 09:20:26 +0200Numerical integration in a functionhttps://ask.sagemath.org/question/7660/numerical-integration-in-a-function/ f(x,y)=numerical_integral(1/d*2*x*y,.01,Infinity)[0]
Error
So what I want is to the integration wait until after the variables have been substituted so that it is able to numerically integrate. (Yes I need to numerically integrate. This is a simplified form that reproduces the same result.)
f(3,1)=numerical_integral(1/d*2*3*1,.01,Infinity)[0]
406.69135669845798
I thought there might be a way using a lambda defined function, but I was unable to find one.willmwadeWed, 01 Sep 2010 09:20:26 +0200https://ask.sagemath.org/question/7660/Double Integralhttps://ask.sagemath.org/question/7636/double-integral/So I have equations:<br />
B(x,d,h,G)=(a01+b01*x+c01*x^2+d01*x^3) + (a02+b02*x+c02*x^2+d02*x^3)*h + (a11+b11*x+c11*x^2+d11*x^3)*(G/d) + (a12+b12*x+c12*x^2+d12*x^3)*(G/d)*h + (a21+b21*x+c21*x^2+d21*x^3)*(G/d)^2 + (a22+b22*x+c22*x^2+d22*x^3)*((G/d)^2)*h
normal(x,av,sd)=(1/(sd*sqrt(2*pi)))*exp(-(x-av)^2/(2*sd^2))
brk(x,d,h,D,H,Dstd,Hstd,G)=B(x,d,h,G)*normal(d,D,Dstd)*normal(h,H,Hstd)
(a##-d## are all decimals)
And I want to double integrate over d and h. So just for example I can integrate over just d:
f(x) = break1(x,d,11.16,2.85,11.16,0.61,13.85,.5).integrate(d,0,infinity)
f(500).numerical_approx()
1.04299933381999
and it evaluates just fine. Likewise if I put in an value for d and integrate over h, it also produces a value.
So I want the numerical approximation of this double integral, but when I try for it using:
f(x) = break1(x,d,h,2.85,11.16,0.61,13.85,.5).integrate(d,0,infinity).integrate(h,0,infinity)
f(500).numerical_approx()
/home/wil/sage/local/lib/python2.6/site-packages/sage/symbolic/integration/integral.pyc in _evalf_(self, f, x, a, b, parent)
199 # The gsl routine returns a tuple, which also contains the error.
200 # We only return the result.
--> 201 return numerical_integral(f, a, b)[0]
202
203 def _tderivative_(self, f, x, a, b, diff_param=None):
/home/wil/sage/local/lib/python2.6/site-packages/sage/gsl/integration.so in sage.gsl.integration.numerical_integral (sage/gsl/integration.c:1551)()
ValueError: Integrand has wrong number of parameters
At any rate, I think what is happening is that it is trying to evaluate the inside integral numerically first perhaps, which it is not able to do as it has a variable?
I tried using the lambda in the first answer, and I was able to evaluate, but I had to set it to max_points=10 to get an answer that was even close to correct, plus I could find no way to plot that one.
Thanks for any help!
WilwillmwadeWed, 25 Aug 2010 16:49:41 +0200https://ask.sagemath.org/question/7636/