# dwavefunction: Wave Function Density In wavefunction: Wave Function Representation of Real Distributions

## Description

Evaluate the density of a wave function model

## Usage

 `1` ```dwavefunction(x, w, log = FALSE, amplitude = FALSE) ```

## Arguments

 `x` a numeric vector `w` a vector of coefficients from `wavefunction_fit` `log` if `TRUE`, returns the log density instead of the density `amplitude` if `TRUE`, returns the amplitude (or the log of the absolute value of the amplitude) instead of the density. The density is the squared amplitude, but the amplitude may be positive or negative.

## Details

The elements of the returned vector p are (when `log` and `amplitude` are `FALSE`):

p[i] = (w H(x) / e + ... + w[K+1] H[k](x) / e[K+1])^2 * exp(-x^2) where e[k] = sqrt(sqrt(pi) * 2^k * k!)

Here, K is the maximum degree, equal to `length(w)-1`, and H[k] is the Hermite polynomial of degree k. Note that `w`, being an R vector, is one-indexed, so w[k] is associated with the Hermite polynomial of degree k-1.

## Value

a numeric vector of the same length as `x`

 ```1 2 3``` ``` x <- rnorm(100) w <- wavefunction_fit(x, degree = 6) p <- dwavefunction(x, w) ```