
Re: How to calculate the partial derivative?
Posted:
Nov 21, 2012 4:08 AM


Dear Dr. M. Abbasi,
Thank you very much for your kindly reply. I tested your code, it works! Howerver, I still didn't understand your code, could you give me some more explains? In addition, I write similar code according to your format, it doesn't work, could you please help me to take a look at it?
Thanks, Tang Laoya
Clear["Global`*"]; eq1 = L1 == (a1 + b1 x + c1 y + d1 z)/6/V; eq2 = L2 == (a2 + b2 x + c2 y + d2 z)/6/V; eq3 = L3 == (a3 + b3 x + c3 y + d3 z)/6/V; eq4 = L4 == (a4 + b4 x + c4 y + d4 z)/6/V; lhs[eq_] := eq /. (lhs_ == rhs_) > lhs; rhs[eq_] := eq /. (lhs_ == rhs_) > rhs;
nod = 10; NN = Table[0, {nod}]; NN[[1]] = rhs[eq1] (2 rhs[eq1]  1); NN[[2]] = rhs[eq2] (2 rhs[eq2]  1); NN[[3]] = rhs[eq3] (2 rhs[eq3]  1); NN[[4]] = rhs[eq4] (2 rhs[eq4]  1); NN[[5]] = 4 rhs[eq1] rhs[eq2]; NN[[6]] = 4 rhs[eq2] rhs[eq3]; NN[[7]] = 4 rhs[eq3] rhs[eq1]; NN[[8]] = 4 rhs[eq3] rhs[eq4]; NN[[9]] = 4 rhs[eq4] rhs[eq1]; NN[[10]] = 4 rhs[eq2] rhs[eq4];
DNx = D[NN, x]; DNx = DNx /. {rhs[eq1] > lhs[eq1], rhs[eq2] > lhs[eq2], rhs[eq3] > lhs[eq3], rhs[eq4] > lhs[eq4]}
DNy = D[NN, y]; DNy = DNy /. {rhs[eq1] > lhs[eq1], rhs[eq2] > lhs[eq2], rhs[eq3] > lhs[eq3], rhs[eq4] > lhs[eq4]}
DNz = D[NN, z]; DNz = DNz /. {rhs[eq1] > lhs[eq1], rhs[eq2] > lhs[eq2], rhs[eq3] > lhs[eq3], rhs[eq4] > lhs[eq4]}
On Wednesday, November 21, 2012 2:15:07 PM UTC+8, Tang Laoya wrote: > Dear all, > > > > I am trying to calculate the partial derivative by mathematica, I have the following commands: > > L1=a1+b1*x+c1*y; > > L2=a2+b2*x+c2*y; > > L3=a3+b3*x+c3*y; > > > > NN=L1*L2; > > > > DNx=D[NN,x]; > > > > I got the following result: > > DNex=b2 (a1+b1 x+c1 y)+b1 (a2+b2 x+c2 y) > > > > How to do to have the following result? > > > > DNex=b2*L1 + b1 * L2 > > > > > > Thanks, > > Tang Laoya

