Comments (5)
Hi Jiahao,
An implementation of the gamma function in ApproxFun would look something like this:
Gamma100(x) = sum(Fun(t->t^(x-1)*exp(-t),JacobiWeightSpace(x-1-ceil(x-1),0.,UltrasphericalSpace{0}([0.,100.]))))
@show [Gamma100(5) factorial(4)]
@show [Gamma100(0.5) sqrt(π)]
At this time, functions defined on the Ray
type don't have an integration method, but to take care of the algebraic singularity at the origin, JacobiWeightSpace
will do the trick.
from approxfun.jl.
Forgot sum() was implemented.. that was a pull request from Mikael, right?
Just wanted to add the other implementation we talked about yesterday
x=Fun(identity,[0.,1000.])
α=0.123
f=x^(α-1)*exp(-x)
D=Derivative(space(f))
u=D\f
last(u)
When both endpoints have singularities cumsum will be more difficult. Chebfun subdivides the interval in two, which I guess is sufficient.
On 26 Nov 2014, at 5:08 am, Richard Mikael Slevinsky [email protected] wrote:
Hi Jiahao,
An implementation of the gamma function in ApproxFun would look something like this:
Gamma100(x) = sum(Fun(t->t.^(x-1).*exp(-t),JacobiWeightSpace(x-1-ceil(x-1),0.0,UltrasphericalSpace{0}([0.0,100.0]))))
@show [Gamma100(5) factorial(4)]
@show [Gamma100(0.5) sqrt(π)]
At this time, the Ray type doesn't have an integration method, but to take care of the algebraic singularity at the origin, JacobiWeightSpace will do the trick.—
Reply to this email directly or view it on GitHub #46 (comment).
from approxfun.jl.
Here’s an alternative approach for indefinite integral for functions with singularities at both ends:
x=Fun(identity)
α=2.4;β=1.3;
f=(1+x)^(α-1)(1-x)^(β-1)
w1=exp(-40x^2)(1+x)^(α-1)(1-x)^(β-1)
w2=Fun(x->exp(-40x^2)(1+x)^(α-1)_(1-x)^(β-1))
c=sum(f)/sum(w1)
v=f-w1_c
D=Derivative(space(v))
u=D\v;
u=c*cumsum(w2)⊕u
u[.1]-0.554308241151084127 #-1.1102230246251565e-16
The result is accurate to 16 digits compared to NIntegrate with high precision. (The implementation beat NIntegrate’s default!) ⊕ is a just added syntax for adding functions from two different spaces (by interlacing coefficients). At some point this might make sense as what + should do if spaces are not compatible. But right now “not compatible” means an error is thrown…so hard to check
On 26 Nov 2014, at 10:38 am, Sheehan Olver [email protected] wrote:
Forgot sum() was implemented.. that was a pull request from Mikael, right?
Just wanted to add the other implementation we talked about yesterday
x=Fun(identity,[0.,1000.])
α=0.123
f=x^(α-1)*exp(-x)
D=Derivative(space(f))
u=D\f
last(u)When both endpoints have singularities cumsum will be more difficult. Chebfun subdivides the interval in two, which I guess is sufficient.
On 26 Nov 2014, at 5:08 am, Richard Mikael Slevinsky <[email protected] mailto:[email protected]> wrote:
Hi Jiahao,
An implementation of the gamma function in ApproxFun would look something like this:
Gamma100(x) = sum(Fun(t->t.^(x-1).*exp(-t),JacobiWeightSpace(x-1-ceil(x-1),0.0,UltrasphericalSpace{0}([0.0,100.0]))))
@show [Gamma100(5) factorial(4)]
@show [Gamma100(0.5) sqrt(π)]
At this time, the Ray type doesn't have an integration method, but to take care of the algebraic singularity at the origin, JacobiWeightSpace will do the trick.—
Reply to this email directly or view it on GitHub #46 (comment).
from approxfun.jl.
Just checked in updates so now the following work. Still need to do singularities + ray. @ajt60gaibb
Gaussian on the half line
f=Fun(x->exp(-x^2),[0.,Inf])
cf=cumsum(f)
sum(f)-sqrt(π)/2 # 3.0989533161829286e-10
PyPlot.plt.hist(sample(f,1000))
Singularity
x=Fun(identity,[0.,30.])
α=0.123
f=(x^(α-1)*exp(-x))
u=cumsum(f)
last(u)-gamma(α) # -3.4638958368304884e-14
Beta functions
x=Fun(identity,[0.,1.])
α=2.4;β=1.3;
f=x^(α-1)*(1-x)^(β-1)
cf=cumsum(f)
cf[.1]-0.0016226562099643412 # 3.0357660829594124e-18
x=Fun(identity,[0.,1.])
α=0.5123;β=0.423;
f=x^(α-1)*(1-x)^(β-1)
cumsum(f)[.1]-0.6123555368287131 # -1.5543122344752192e-15
Sampling Beta function
setplotter(“PyPlot”)
plot(f/sum(f))
PyPlot.plt.hist(sample(f,2000),normed=true,bins=[0.:.01:1.])
On 26 Nov 2014, at 10:39 am, Sheehan Olver [email protected] wrote:
Here’s an alternative approach for indefinite integral for functions with singularities at both ends:
x=Fun(identity)
α=2.4;β=1.3;
f=(1+x)^(α-1)(1-x)^(β-1)
w1=exp(-40x^2)(1+x)^(α-1)(1-x)^(β-1)
w2=Fun(x->exp(-40x^2)(1+x)^(α-1)_(1-x)^(β-1))
c=sum(f)/sum(w1)
v=f-w1_c
D=Derivative(space(v))
u=D\v;
u=c*cumsum(w2)⊕uu[.1]-0.554308241151084127 #-1.1102230246251565e-16
The result is accurate to 16 digits compared to NIntegrate with high precision. (The implementation beat NIntegrate’s default!) ⊕ is a just added syntax for adding functions from two different spaces (by interlacing coefficients). At some point this might make sense as what + should do if spaces are not compatible. But right now “not compatible” means an error is thrown…so hard to check
On 26 Nov 2014, at 10:38 am, Sheehan Olver <[email protected] mailto:[email protected]> wrote:
Forgot sum() was implemented.. that was a pull request from Mikael, right?
Just wanted to add the other implementation we talked about yesterday
x=Fun(identity,[0.,1000.])
α=0.123
f=x^(α-1)*exp(-x)
D=Derivative(space(f))
u=D\f
last(u)When both endpoints have singularities cumsum will be more difficult. Chebfun subdivides the interval in two, which I guess is sufficient.
On 26 Nov 2014, at 5:08 am, Richard Mikael Slevinsky <[email protected] mailto:[email protected]> wrote:
Hi Jiahao,
An implementation of the gamma function in ApproxFun would look something like this:
Gamma100(x) = sum(Fun(t->t.^(x-1).*exp(-t),JacobiWeightSpace(x-1-ceil(x-1),0.0,UltrasphericalSpace{0}([0.0,100.0]))))
@show [Gamma100(5) factorial(4)]
@show [Gamma100(0.5) sqrt(π)]
At this time, the Ray type doesn't have an integration method, but to take care of the algebraic singularity at the origin, JacobiWeightSpace will do the trick.—
Reply to this email directly or view it on GitHub #46 (comment).
from approxfun.jl.
The following now works to 12 digits (not sure how to fix the extra digits of error..)
sum(Fun(x->x^0.1*exp(-x),JacobiWeightSpace(0.1,0.,[0.,Inf])))-gamma(1.1)
from approxfun.jl.
Related Issues (20)
- Precompile fails on binder HOT 1
- Domain properties of functions not consistent HOT 2
- Document about solving Volterra equation (second kind) HOT 8
- Trouble with the Fourier representaion of a constant matrix with trailing zero element HOT 2
- Tag v1, write JOSS paper? HOT 1
- WARNING: both ApproxFunFourier and DomainSets export "Disk"; uses of it in module ApproxFun must be qualified HOT 1
- An issue with the built-in solver using ultraspherical spectral method
- Add the option to specify the number of coefficients HOT 2
- Newton for simple PDE gives NaN result HOT 1
- Cumsum fails when used on the output of sign()
- Rounding errors lead to empty domain error when using abs
- Changing operand order causes incorrect calculation of the infinity norm
- Creating a Fun of tanh returns the zero Fun HOT 2
- Division by Fun with root fails: `setdomain(::PiecewiseSpace,::ClosedInterval)` not implement
- L2 operator
- typos HOT 1
- Array concatenations produce unexpected results HOT 1
- Multivariate function roots HOT 12
- Cannot use `Integral` in Newton solver HOT 5
- Wrong tensor product between Fourier and Chebyshev HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from approxfun.jl.