2
$\begingroup$

I want to map this function (1 - num2/num1)*100 to a list. I used the command below, but the command does not work. Can anyone help?

length = Quantity[List[45, 66, 74.6, 45, 34, 34.4], "Meters"]

The function is:

(1 - #[[1]]/#[[2]])*100 & /@ length

for example1: (1-45/no num)*100 = empty

for example2: (1-66/45)*100 = 46.66

for example3: (1-74/66)*100 = 12.12

&...

$\endgroup$
0

1 Answer 1

5
$\begingroup$

Your example has an error: 1-66/45 is negative (so 66/45-1 ?). I guess you want to use BlockMap for this:

list = List[45, 66, 74.6, 45, 34, 34.4];
length = Quantity[#, "Meters"] & /@ list;
BlockMap[(#[[2]]/#[[1]] - 1) 100 &, length, 2, 1] // N

results into

{46.6667, 13.0303, -39.6783, -24.4444, 1.17647}

Or use Ratios:

(Ratios[Quantity[List[45, 66, 74.6, 45, 34, 34.4], "Meters"]] - 1.0) 100
$\endgroup$
1
  • $\begingroup$ Thank you SHuisman, for help. $\endgroup$
    – Erfan
    Sep 29 at 12:01

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.