Game Maker Games, Articles, Tutorials & More

Game Maker Network


Howdy, Guest! Please sign in or register an account.

Print

matrix_exponential

By Daniel · January 1, 2009

Returns the exponential of some square matrix M. This should both a ds_grid filled with real entries.

This script uses the simple optimization of M^(2n) = (M^n)*(M^n), so it consumes O(log n) time. It does not attempt to diagonalize M for further optimization.

Relies on matrix_identity and matrix_product -- make sure you have these scripts beforehand.

/* matrix_exponential(M, exp)
 *
 * Returns the exponential of some square matrix M. This should both a ds_grid
 * filled with real entries.
 *
 * This script uses the simple optimization of M^(2n) = (M^n)*(M^n), so it
 * consumes O(log n) time. It does not attempt to diagonalize M for further
 * optimization.
 */

if (argument1 == 0)
  return matrix_identity(ds_grid_width(argument0));

if (argument1 == 1)
  return argument0;

if (argument1 & 1)
  return matrix_product(argument0, matrix_exponential(argument0, argument1 - 1));

var root; root = matrix_exponential(argument0, argument1 / 2);
return matrix_product(root, root);

Categories: Mathematics

Comments

There are no comments to display.

Post a Comment

You must be signed in to post comments.

Advertisement