Group Abstract Group Abstract

Message Boards Message Boards

0
|
1.7K Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

Allocating multiple matrices in a variable

I think my problem is rather easy to solve, but I have yet to come across a solution. I have a function which is in form of a matrix dependent on one variable. What I want is to evaluate this function for multiple values of this variable and store all of the resulting matrices in another variable (like a list of matrices). I couldn't quite figure out how to use the For loop for it, since I want to be able to call each matrix in the order they were generated. Thanks in advance.

Posted 6 years ago

Hi Carlos,

If you have a function and want to evaluate it for several different values, map the function over a list of those values.

f1[n_] := n*n;
f1 /@ {1, 3, 6}
(* {1, 9, 36} *)

f2[n_] := RandomInteger[{-n, n}, {2, 2}]
f2 /@ {3, 5, 9}
(* {{{2, 1}, {-3, 0}}, {{1, 3}, {1, 0}}, {{-4, 4}, {-5, 0}}} *)
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard