integrating a list




This is what I came up with:



--------------- begin Maxima script and output --------------------

ListTrapInt():=block(if i>0 then z:z+(v[i][2]+v[i+1][2])/2*dt, i:i+1, [v[i][1],z])$

i:0$ z:0$ dt:1$? v: [[0,0],[1,1],[2,2],[3,3],[4,4],[5,5]]$
x: makelist(ListTrapInt(),length(v));
??????????????????????????? 1?????????????? 9?????????????? 25
(%o1)????????? [[0, 0], [1, -], [2, 2], [3, -], [4, 8], [5, --]]
??????????????????????????? 2?????????????? 2?????????????? 2


---------------------- end -----------------------------------------




________________________________
 From: Jaime Villate <villate at fe.up.pt>
To: Ether Jones <maxima at etherjones.us> 
Cc: maxima <maxima at math.utexas.edu> 
Sent: Tuesday, September 17, 2013 5:09 PM
Subject: Re: [Maxima] integrating a list
 


On 17-09-2013 18:48, Ether Jones wrote:

I have a list of ordered pairs (t,speed) representing the speed of an object vs time.
>
>
>Is there a built-in Maxima function to generate the associated list of ordered pairs (t,distance)?
>
>
>The "t" values are equally spaced apart.
>
>
Hi,
I'm not aware of any built-in functions, but you could implement the
    trapezoid (or other) rule:


list_integrate(x) := block([y: [[x[1][1], 0]]],
??????????????? for i:2 thru length(x) do
???????????????????? y:endcons( [x[i][1], y[i-1][2] + (x[i][1]-x[i-1][1])*(x[i-1][2] + x[i][2])/2],y),
? ? ? ? ? ? ? ? y)$
and use it like this:

list_integrate( [[1,4], [2,3], [3,6]] )?? ----> [[1,0], [2,7/2],
    [3,8]]

I hope this helps. Regards,
Jaime