
Re: How to calculate the partial derivative?
Posted:
Nov 21, 2012 5:17 AM


On 11/21/2012 3:08 AM, Tang Laoya wrote:
> 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? >
The reason it does not work as is in your second example, is because this is a typical subexpression finding and replacement issues in all CAS systems.
The expression you want to replace is there, but it is now build into the over all more complex expression you have (not like the simpler example you had before, where the expression we wanted to replace was there as is)
Hence, one needs to do more work to extract these expressions out and replace them back with your L1 and L2 using pattern rules.
For example, looking at part of one of your expressions below
> > DNx = D[NN, x]; > DNx = DNx /. {rhs[eq1] > lhs[eq1], rhs[eq2] > lhs[eq2], > rhs[eq3] > lhs[eq3], rhs[eq4] > lhs[eq4]} >
b1*(a1 + b1*x + c1*y + d1*z))/(18* V^2) + (b1*(1 + (a1 + b1*x + c1*y + d1*z)/(3*V)))/(6*V)
and we want now to replace the following subexpressions (a1 + b1*x + c1*y + d1*z)/6/V and (a2 + b2 x + c2 y + d2 z)/6/V
with L1 and L2. So you see there is /18*V^2 in the denominator while the expression we want to replace has /6*V. So a factoring out is needed or such operation.
Since we are using pattern matching replacement, Mathematica is looking for the exact pattern and it can't find it.
So, one needs to do more work on the final expression to be able to find those patterns you want to replace with L1 and L2. May be a combination of Simplify/Factor/Collect etc..
If I see an easy way to do this, will post an answer. But I am not an expert in this subject, so may be there is a better approach to this whole issue that avoids these problem from first place.
good luck!
Nasser

