|
| 1 | +# This file is a part of AstroLib.jl. License is MIT "Expat". |
| 2 | + |
| 3 | +function _imf{T<:AbstractFloat}(mass::AbstractVector{T}, expon::AbstractVector{T}, |
| 4 | + mass_range::AbstractVector{T}) |
| 5 | + ne_comp = length(expon) |
| 6 | + if length(mass_range) != ne_comp + 1 |
| 7 | + error("Length of array mass_range is not one more than that of expon") |
| 8 | + end |
| 9 | + integ = Vector{T}(ne_comp) |
| 10 | + joint = ones(T, ne_comp) |
| 11 | + for i = 1:ne_comp |
| 12 | + if expon[i] != -1 |
| 13 | + integ[i] = (mass_range[i+1]^(1 + expon[i]) - mass_range[i]^(1 + expon[i]))/ |
| 14 | + (1 + expon[i]) |
| 15 | + else |
| 16 | + integ[i] = log(mass_range[i+1]/mass_range[i]) |
| 17 | + end |
| 18 | + if i != 1 |
| 19 | + joint[i] = joint[i-1]*(mass_range[i]^(expon[i-1] - expon[i])) |
| 20 | + end |
| 21 | + end |
| 22 | + norm = joint./(dot(integ, joint)) |
| 23 | + psi = zeros(mass) |
| 24 | + for i = 1:ne_comp |
| 25 | + test = find(mass_range[i].< mass.<mass_range[i+1]) |
| 26 | + if length(test) !=0 |
| 27 | + psi[test] = norm[i].*(mass[test].^expon[i]) |
| 28 | + end |
| 29 | + end |
| 30 | + return psi |
| 31 | +end |
| 32 | + |
| 33 | +""" |
| 34 | + imf(mass, expon, mass_range) -> psi |
| 35 | +
|
| 36 | +### Purpose ### |
| 37 | +
|
| 38 | +Compute an N-component power-law logarithmic initial mass function (IMF). |
| 39 | +
|
| 40 | +### Explanation ### |
| 41 | +
|
| 42 | +The function is normalized so that the total mass distribution equals |
| 43 | +one solar mass. |
| 44 | +
|
| 45 | +### Arguments ### |
| 46 | +
|
| 47 | +* `mass`: mass in units of solar mass, vector. |
| 48 | +* `expon`: power law exponent, vector. The number of values in expon equals |
| 49 | + the number of different power-law components in the IMF. |
| 50 | +* `mass_range`: vector containing the mass upper and lower limits of the |
| 51 | + IMF and masses where the IMF exponent changes. The number of values in |
| 52 | + mass_range should be one more than in expon. The values in mass_range |
| 53 | + should be monotonically increasing and positive. |
| 54 | +
|
| 55 | +### Output ### |
| 56 | +
|
| 57 | +* `psi`: mass function, number of stars per unit logarithmic mass interval |
| 58 | + evaluated for supplied masses. |
| 59 | +
|
| 60 | +### Example ### |
| 61 | +
|
| 62 | +Show the number of stars per unit mass interval at 3 Msun for a Salpeter |
| 63 | +(expon = -1.35) IMF, with a mass range from 0.1 MSun to 110 Msun. |
| 64 | +
|
| 65 | +```julia |
| 66 | +julia> imf([3], [-1.35], [0.1, 110]) / 3 |
| 67 | +1-element Array{Float64,1}: |
| 68 | + 0.0129414 |
| 69 | +``` |
| 70 | +
|
| 71 | +### Notes ### |
| 72 | +
|
| 73 | +Code of this function is based on IDL Astronomy User's Library. |
| 74 | +""" |
| 75 | +imf(mass::AbstractVector{<:Real}, expon::AbstractVector{<:Real}, mass_range::AbstractVector{<:Real}) = |
| 76 | + _imf(float(mass), float(expon), float(mass_range)) |
0 commit comments