first time user and not quite familiar with how to enter my code here properly, but this isn't lengthy..
I have a previously defined function that computes the total time it takes to ride a bike with given parameters distance and speed..
Clear[biketime, distance, speed]
biketime[distance_, speed_] := distance/speed
So biketime[10,2]
would refer to 5 (minutes)
Now, what if I wanted to pass a list into this function using replacement rules? I have given an attempt which now looks like:
Clear[biketime, distance, speed, list]
biketime[distance_, speed_] := distance/speed
totaltime[list_] := list /. List -> Plus[ biketime[distance, speed]]
totaltime[{10, 2}, {15, 3}]
All I get as an output is totaltime[{10,2 }, {15, 3}]
, when I want the output to be those 2 pieces of data added together, so my output would be 10... Either something isn't defined properly or I'm just completely wrong and the function isn't doing what I think it is doing in my head.
Any suggestions? Sorry about the messy code.
Apply
on the first level (shorthand notation:@@@
):biketime @@@ {{10, 2}, {15, 3}}
yields{5, 5}
. If you want to sum the output, tryTotal
. $\endgroup$