Re: Vector and Matrix Differentiation with Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg22297] Re: [mg22284] Vector and Matrix Differentiation with Mathematica
- From: Hartmut Wolf <hwolf at debis.com>
- Date: Thu, 24 Feb 2000 03:01:14 -0500 (EST)
- Organization: debis Systemhaus
- References: <200002230601.BAA22821@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Johannes Ludsteck schrieb: > > Dear Mathgroup Members, > I have to compute derivatives of functions including vectors and > matrices. To the best of my knowledge Mathematica doesn't > support this fully. > > For example, If b is a vector and A a conformable square matrix, > D[b . A . b, b] > should evaluate to A + Transpose[A]. > Mathematica returns > 0.A.b + 2 1.0.b + 2 1.A.1 + 2 b.0.1 + b.0.b + b.A.0 > > With some additional Rules you get a more sensible result: > > D[D[b.A.b, b], b] > //. {Dot[___, 0, ___] -> 0, Dot[x___, 1, y___] -> Dot[x, y]} > > Evaluates to 2 A. This is, of course, true only if A is symmetric. > I don't claim that Mathematica makes an error here. > Rather my Rules seem to be buggy. > (However a reason for the problem might be that Mathematica > doesn't keep track of vector dimensions, i.e. Mathematica doesn't > distinguish between row and column vectors.) > Since I assume that I will have to invest some time to supply the > rigth rules, I ask, whether someone of you has written a package, > which does my jobs or can provide any experience with matrix > calculus in Mathematica. > Dear Johannes, when I do Dt on Dot I get In[9]:= Dt[b.A.b, b] Out[9]= 1.A.b + b.A.1 + b.Dt[A, b].b which is perfectly right, considered the fact that Mathematica has not been told what either b or A are. If you do, you also should know very well what ... In[10]:= D[b, b] Out[10]= 1 ... really is. If you substitute this "1" into Out[9] you'll have a 100% correct result. However if you define In[11]:= A = Array[a, {3, 3}]; b = Table[cb[i, t], {i, 3}]; and now take the derivative In[13]:= D[b.A.b, t] Out[13]= .... compared to In[14]:= D[b, t].A.b + b.A.D[b, t] Out[14]= .... In[15]:= % == %% Out[15]= True Hope to have helped, kind regards, Hartmut
- References:
- Vector and Matrix Differentiation with Mathematica
- From: "Johannes Ludsteck" <ludsteck@zew.de>
- Vector and Matrix Differentiation with Mathematica