Assuming that your data has the form
{String, number, number, number, {number,..., number}}
rather than what you have actually posted, then perhaps the following will help you.
f[list_List] :=
Module[{dist},
dist = Norm[list[[4]] - list[[3]]];
{list[[1]], list[[5]]*list[[2]]/dist}]
Now let's cook up some data.
data = {#, 42., 3., 5., Range[2.5, 6., 1.1]} & /@ CharacterRange["A", "D"]
{{"A", 42., 3., 5., {2.5, 3.6, 4.7, 5.8}},
{"B", 42., 3., 5., {2.5, 3.6, 4.7, 5.8}},
{"C", 42., 3., 5., {2.5, 3.6, 4.7, 5.8}},
{"D", 42., 3., 5., {2.5, 3.6, 4.7, 5.8}}}
Now we can process all the data by mapping f
over the data list.
f /@ data
{{"A", {52.5, 75.6, 98.7, 121.8}},
{"B", {52.5, 75.6, 98.7, 121.8}},
{"C", {52.5, 75.6, 98.7, 121.8}},
{"D", {52.5, 75.6, 98.7, 121.8}}}
Notes
Don't use Do
to make a compound expression. It is an iterating construct not a grouping construct. Believe it or not, semicolon ( ; ) is the grouping operator in Mathematica, not a delimiter as it in many other programming languages. Reference: CompoundExpression
Module
is the Mathematica construct used to group code when you want break the code up into steps by assigning partial results to local variables. Hence, Module[{dist}, ...]
.
You almost never need to use Return
because a function normally returns the last expression that it evaluates. Hence, {list[[1]], list[[5]]*list[[2]]/dist}
is return by f
.
Here are some links to documentation pages that will help you understand what I done.
http://reference.wolfram.com/language/howto/MapAFunctionOverAList.html
http://reference.wolfram.com/language/tutorial/FunctionsAsProcedures.html
What are the most common pitfalls awaiting new users?
Map
your function over this list. $\endgroup$list[[2]]
will be a string. Yet in your code you do arithmetic with it. That seems wrong to me. Can you clarify? $\endgroup$