GithubHelp home page GithubHelp logo

Comments (5)

MikaelSlevinsky avatar MikaelSlevinsky commented on May 18, 2024

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.

dlfivefifty avatar dlfivefifty commented on May 18, 2024

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.

dlfivefifty avatar dlfivefifty commented on May 18, 2024

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.

dlfivefifty avatar dlfivefifty commented on May 18, 2024

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)⊕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] 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.

dlfivefifty avatar dlfivefifty commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.