0
$\begingroup$

I have a data file which I have imported and form a table.

list1 = Flatten[Table[{relic[[i]]}, {i, 1, 5}], 1]

the output looks like this

{{4.992596228629734*^-14}, {9.985192457259468*^-14},{1.49777886858892*^-13}, {1.9970384914518936*^-13}, {2.496298114314867*^-13}}

I have another list

masslist =  Reap[For[i = 2, i <= 50, i = i + 10, Sow[i]];][[2, 1]]~Partition~1

output is

{{2}, {12}, {22}, {32}, {42}}

Now I want to form another table by multiplying the elements of the two lists. I used this

newlist =  Table[{masslist[[i, 1]], masslist[[i, 1]]*list1[[i, 1]]}, {i, 1, Length[masslist]}]

But that is not working. It gives an output like this

{{2, 2 4.992596228629734*^-14}, {12, 12 9.985192457259468*^-14}, {22, 22 1.49777886858892*^-13}, {32,32 1.9970384914518936*^-13}, {42, 42 2.496298114314867*^-13}}

I think is not working because of the number format of the first list. Can you please help?

$\endgroup$
3
  • $\begingroup$ masslist = List /@ Range[2,50,10] is the Mathematica way of doing it (not asking why you want the elements to be lists...). For me the rest works fine, you may have some conflicting definitions - try a fresh session. $\endgroup$
    – gwr
    Jan 28, 2019 at 11:52
  • $\begingroup$ Please add all the definitions (e.g. what is relic?) so that people can reproduce your results. $\endgroup$
    – gwr
    Jan 28, 2019 at 11:53
  • 1
    $\begingroup$ Try Head@list1[[1,1]] to verify that you have a Real number. If not, then you may need to use ToExpression[] or equivalent. $\endgroup$
    – Somos
    Jan 28, 2019 at 12:47

1 Answer 1

1
$\begingroup$

Mathematica has constructs that are more powerful than C:

(* make up a list called relic *)
relic = Range[1, 7, 1]

(* {1,2,3,4,5,6,7} *)

(* create massList *)
massList = Range[2, 50, 10]

(* {2,12,22,32,42} *)

(* multiply massList by a corresponding length of relic *)
product = massList Take[relic, Length[massList]]

(* {2,24,66,128,210} *)

Kind regards, David

$\endgroup$

Your Answer

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

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