Question: Procedure for differentiation on Lists; Error, illegal use of an object as a name

Hi,

I tried to write a procedure which performs a differentiation on list elements:

 

list1:= [x^3 , 2x , 3]
list2:= [x^5, 2x^4 , 2x]

 



dList:=proc(a::list, b::list)::list;
    local res::list, i::integer, n::integer; 
    description "add list elements and diff";
    n:=min(nops(a), nops(b)) ;
res:=[seq(0, i=1..n)];
for i from 1 by 1 to n do
     res[i]:=diff(a[i]+b[i],x)
end do;
res;
end proc:


dList(list1,list2)

However the Line:  res[i]:=diff(a[i]+b[i],x)

 

causes the Error: Error, illegal use of an object as a name;

 

Can someone give me a hint how to fix this?

 

Thank you very much.

Please Wait...