You are currently viewing the GMLscripts.com static mirror. Forum access and script submissions are not available through this mirror.

Invert GMLscripts.com

ds_list_sum_squares

Returns the sum of squares of all values in a given list.

$$\large \Sigma{x^2}=x_1^2+x_2^2+\cdots+x_n^2$$

NOTE: For the statistical data analysis function see: ds_list_sum_of_squares.

ds_list_sum_squares(list)
Returns the sum of squares of all values in a given list.
COPY/// @func   ds_list_sum_squares(list)
///
/// @desc   Returns the sum of squares of all values in a given list.
///         If the list is empty, undefined is returned.
///
/// @param  {list}      list        list data structure
///
/// @return {real}      sum of values squared
///
/// GMLscripts.com/license

function ds_list_sum_squares(list)
{
    var n = ds_list_size(list);
    if (n == 0) return undefined;

    var sum = 0;

    for (var i=0; i<n; i++) sum += sqr(ds_list_find_value(list, i));

    return sum;
}

Contributors: xot

GitHub: View · Commits · Blame · Raw