Question: Looping over lists and sets

Write a procedure rsum that sums the reciprocals of the elements of a list.  So rsum( [a,b,c] ) should return 1/a + 1/b + 1/c.

How would i modify my code so that it does this... I know theres a much simpler way (rsum := L -> add( 1/x, x in L ):) but i would like to know how to edit the one ive done.

Heres my code so far...

rsum := proc(L)
local n;
    for n in L do
      1/n
    end do;
end proc;

 

I think I have to define (for ex), N, as something then have...

for n in L do

  N, 1/n.

Any help on this please?

Please Wait...