programming in maxima




On Wed, 30 Dec 2009, r Rishikesh wrote:

< I want to write a function which computes derivative given a list.
< Consider the following situation:
< 
< (%i1) array(x,10);
< 
< (%o1) x
< (%i2) expr: product(1+x[i]^i,i,1,10);
< 
< (%o2) (x[1]+1)*(x[2]^2+1)*(x[3]^3+1)*(x[4]^4+1)*(x[5]^5+1)*(x[6]^6+1)
<               *(x[7]^7+1)*(x[8]^8+1)*(x[9]^9+1)*(x[10]^10+1)
< (%i3) l:[1,1,2];
< 
< (%o3) [1,1,2]
< 
< I want to write a function f
< 
< f(expr,l)  should compute diff(expr,x[1],1,x[2],1,x[3],2)
< 
< I can create a list as below
< 
< 
< (%i4) create_list (x[i],i,1,length(l));
< 
< (%o4) [x[1],x[2],x[3]]
< (%i5) join(%,l);
< 
< (%o5) [x[1],1,x[2],1,x[3],2]
< 
< 
< but I am unable to solve beyond this. How can I solve the problem?
 
Try,
(%i13) mdiff(f,l) := apply(diff,append([f],l));

(%o13) mdiff(f,l):=apply(diff,append([f],l))
(%i14) mdiff(expr,[x[1],1,x[2],1,x[3],2]);

(%o14) 'diff(expr,x[1],1,x[2],1,x[3],2)
(%i15) subst(expr=product(1+x[i]^i,i,1,3),%);

(%o15) 'diff((x[1]+1)*(x[2]^2+1)*(x[3]^3+1),x[1],1,x[2],1,x[3],2)
(%i16) ev(%,nouns);

(%o16) 12*x[2]*x[3]

Happy New Year,
Leo

-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.