function normpdf
normpdf(
x: number,
mu?: number,
sigma?: number,
): number

Computes the probability density function (PDF) of a normal distribution.

Returns the PDF of the normal distribution with mean mu and standard deviation sigma, evaluated at x. If mu and sigma are not provided, it defaults to the standard normal distribution (mu = 0, sigma = 1).

Examples

Compute the standard normal PDF at x = 1

import { assertEquals } from "jsr:@std/assert";

assertEquals(normpdf(1), 0.24197072451914337);

Compute normal PDF with custom mean and standard deviation

import { assertEquals } from "jsr:@std/assert";

assertEquals(normpdf(0, 10, 2), 7.433597573671488e-7);

Compute normal PDF at the mean (should be maximum)

import { assertEquals } from "jsr:@std/assert";

assertEquals(normpdf(5, 5, 1), 0.3989422804014327);

Compute normal PDF for a large value (should be small)

import { assertEquals } from "jsr:@std/assert";

assertEquals(normpdf(100, 50, 10), 1.486719514734298e-7);

Compute normal PDF for a negative value

import { assertEquals } from "jsr:@std/assert";

assertEquals(normpdf(-1, 0, 1), 0.24197072451914337);

Parameters

x: number

The value at which to evaluate the PDF

optional
mu: number = 0

The mean of the normal distribution (defaults to 0)

optional
sigma: number = 1

The standard deviation of the normal distribution (defaults to 1)

Return Type

number

The probability density function value at x

Throws

If sigma is not a positive number