Message Boards Message Boards

0
|
4442 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Quickly simulate values and evaluate

Posted 10 years ago
x = {{a + b, b*c}, {c + d, d + (a + c)}}
numx = RandomReal[{0, 1}, {Length[Variables[x]]}]
x /. {a -> numx[[1]], b -> numx[[2]], c -> numx[[3]], d -> numx[[4]]}
Is there a better (more efficient) way to do this?
POSTED BY: Casper YC
2 Replies
Posted 10 years ago
Just another way:
x = {{a + b, b*c}, {c + d, d + (a + c)}};
rep = # -> RandomReal[] & /@ Variables[x];
x /. rep
POSTED BY: Mark Dooris
The following keeps you from having to write out the set of rules in the final expression and so may be valuable for more complicated situations:

x = {{a + b, b*c}, {c + d, d + (a + c)}};

replacements = Thread [Variables[x] -> RandomReal[{0, 1}, {Length[Variables[x]]}]];

x /. replacements

--David
http://scientificarts.com
POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract