Game Maker Games, Articles, Tutorials & More

Game Maker Network


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

Print

matrix_sum

By Daniel · January 1, 2009

Returns the sum of two matrices. These should both be ds_grids filled with real entries.

/* matrix_sum(M1, M2)
 *
 * Returns the sum of two matrices. These should both be ds_grids filled
 * with real entries.
 */

var w, h, S, xx, yy;

w = ds_grid_width(argument0);
h = ds_grid_height(argument0);
S = ds_grid_create(w, h);

for (xx = 0; xx < w; xx += 1)
  for (yy = 0; yy < h; yy += 1)
    ds_grid_set(S, xx, yy, ds_grid_get(argument0, xx, yy) +
                           ds_grid_get(argument1, xx, yy));

return S;

Categories: Mathematics

Comments

There are no comments to display.

Post a Comment

You must be signed in to post comments.

Advertisement