# User-defined distribution function example

**URL:** <https://discourse.julialang.org/t/user-defined-distribution-function-example/22035>\
**Category:** Statistics\
**Tags:** question\
**Created:** [March 19, 2019, 12:01pm UTC](https://discourse.julialang.org/t/user-defined-distribution-function-example/22035 "2019-03-19T12:01:19Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![roi.holtzman](https://avatars.discourse-cdn.com/v4/letter/r/f05b48/32.png) [@roi.holtzman](https://discourse.julialang.org/u/roi.holtzman)\
**Post date:** [March 19, 2019, 3:53pm UTC](https://discourse.julialang.org/t/user-defined-distribution-function-example/22035/3 "2019-03-19T15:53:00Z")

</div>

@alejandromerchan my distribution is x\exp(-x) for x\in (0, \infty)  
If I look at the example code from the [post](https://discourse.julialang.org/t/help-with-creating-a-custom-distribution/13229)

```julia
type MyDist <: ContinuousUnivariateDistribution
    mu::Float64
    sigma::Float64
    MyDist(mu, sigma) = new(Float64(mu), Float64(sigma))
end

pdf(d::MyDist, x::Float64) = pdf(Normal(d.mu, 2*d.sigma), x)

```

I do not understand where should I introduce my function.  
In this code the `Normal` distribution is used, but how to insert a custom function like `f(x)=x*exp(-x)` ?

---

_[View the full topic](https://discourse.julialang.org/t/user-defined-distribution-function-example/22035)._
