Re: A simple question?
- To: mathgroup at smc.vnet.net
- Subject: [mg3644] Re: A simple question?
- From: espen.haslund at fys.uio.no (Espen Haslund)
- Date: Sun, 31 Mar 1996 00:51:45 -0500
- Organization: Universitet i Oslo
- Sender: owner-wri-mathgroup at wolfram.com
In article <4jd5ej$pmr at dragonfly.wolfram.com>, nader at math.chalmers.se says... > > ;> Hi, ;> ;> I guess this must be a simple question, but I can't seem to ;>find a good solution to it. For a function f[x,y] I want to create a ;>2x2x2x2 matrix called fourthDs. The elements of fourthDs will be the ;>fourth derivatives of f with respect to x and y in the following form: ;> ;>fourthDs[[1,1,1,1]]=D[f[x,y],{x,4}] ;>fourthDs[[2,2,2,2]]=D[f[x,y],{y,4}] ;>fourthDs[[1,2,1,1]]=D[f[x,y],{x,3},{y,1}] ;> ;> This simply means that the number of 1's in the index will ;>give the number of derivations with respect to x and the number of 2's ;>in the index will give the number of derivations with respect to y. In ;>this case there will be 5 different elements in fourthDs. For example, ;>the last element in the above list will be the same for ;>fourthDs[[2,1,1,1]], fourthDs[[1,1,2,1]] and so on. :> ;> I wonder how I can do this in Mma. Thanks in advance for your ;>time. > > Regards, Nader Tajvidi > > > Hi, Nader: This is not so elegant: fourthDs[f_, {x_, y_}] := Module[{res}, res = Table[0, {2},{2},{2},{2}]; Do[ res[[i,j,k,l]] = D[f, {x, Length[Select[{i,j,k,l}, # == 1 &] ] }, {y, Length[Select[{i,j,k,l}, # == 2 &] ] }], {i,1,2},{j,1,2},{k,1,2},{l,1,2}]; res ] but I hope it will do what you want. - Espen ==== [MESSAGE SEPARATOR] ====