0
$\begingroup$

I have a list of 8 items the form:

L={{v -> 0.015876}, {v -> 0.214969}, {v -> 0.293763}, {v -> 0.78181}, {v -> 1.8144}, {v -> 1.8144}, {v -> 7.63829}, {v -> 7.68563}}

From this list I would like to create the list:

{{f(v1),v1},...,{f(v8),v8}}

in a nice way (I can do it with a for loop but I wonder if there is (as always) a good way of doing it). $v1,\ldots v8$ correspond to the numerical values of the original list.

I would like to create a function $g$ of two variables $a,v$ and which return ${f(v/.a),v/.a)}$

$\endgroup$
2
$\begingroup$

you can use the intermediate function which will take the data from your list and apply your function f:

g={f@#[[1,2]],#[[1,2]]}&;
g/@L

Output:

{{f[0.015876], 0.015876}, {f[0.214969], 0.214969}, {f[0.293763], 0.293763}, {f[0.78181], 0.78181}, {f[1.8144], 1.8144}, {f[1.8144], 1.8144}, {f[7.63829], 7.63829}, {f[7.68563], 7.68563}}

UPD:

ll=v/.L;
g={f@#,#}&;
g/@ll

gives you the same result.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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