0
$\begingroup$

I have a table with x rows. For one column of the table, I want to add a different random real to each element. I have generated a list of x random real numbers and called it 'tolerance'. Here's the code for the table, and I want to add a different random real from the list 'tolerance' to each radius:

{Print["(set! geometry-lattice (make lattice (size ", sx , " ", sy , 
" no-size)))"];, 
table1 = Table[
Print["(make cylinder (center ", Coord[[1]], " ", Coord[[2]], 
 ")(material (make dielectric (epsilon ", Eps , "))) (radius " , 
 R, + tolerance[[i]] ") (height 1) (axis 0 0 1))"];, {Coord, 
Flatten[LatticeCo, 1]}]}

What I tried was adding the "+tolerance[[i]]" bit, which I thought would take the 1st element of the randomreal list and add it to the radius in the first row, then the second element in the randomreal list and add it to the radius in the second row and so on, but I'm very new to Mathematica and I've really not got the hang of how this works.

Any suggestions would be much appreciated, sorry I haven't posted the whole code, would probably make it easier to help but large chunks of it weren't written by me.

$\endgroup$
1
  • 3
    $\begingroup$ Simple rule: No executable code, no answer. Please remove unnecessary clutter from the code and put in relevant definitions. $\endgroup$ Commented Jan 8, 2018 at 23:55

1 Answer 1

2
$\begingroup$
table1 = Table[RandomInteger[{1, 5}], {5}, {6}];

(*

{{5, 3, 2, 2, 3, 3}, 
 {1, 3, 3, 3, 1, 1}, 
 {1, 2, 5, 1, 5, 1}, 
 {1, 1, 2, 2, 2, 5}, 
 {4, 3, 5, 2, 4, 4}}

*)

randomaddition = Table[RandomReal[], {6}]

(*

{0.563345, 0.198882, 0.13978, 0.0295685, 0.975357, 0.687068}

*)

randomaddition + # & /@ table1

(*

{{5.56335, 3.19888, 2.13978, 2.02957, 3.97536, 3.68707}, 
 {1.56335, 3.19888, 3.13978, 3.02957, 1.97536, 1.68707}, 
 {1.56335, 2.19888, 5.13978, 1.02957, 5.97536, 1.68707}, 
 {1.56335, 1.19888, 2.13978, 2.02957, 2.97536, 5.68707}, 
 {4.56335, 3.19888, 5.13978, 2.02957, 4.97536, 4.68707}}

*)

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.