Changeset 16737
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/DerivativeCalculator.cs
r16565 r16737 83 83 if (branch.SubtreeCount >= 2) { 84 84 var f = (ISymbolicExpressionTreeNode)branch.GetSubtree(0).Clone(); 85 var g = (ISymbolicExpressionTreeNode)branch.GetSubtree(1).Clone();86 85 var fprime = Derive(f, variableName); 87 var gprime = Derive(g, variableName); 88 var fgPrime = Sum(Product(f, gprime), Product(fprime, g)); 89 for (int i = 2; i < branch.SubtreeCount; i++) { 86 for (int i = 1; i < branch.SubtreeCount; i++) { 87 var g = (ISymbolicExpressionTreeNode)branch.GetSubtree(i).Clone(); 90 88 var fg = Product((ISymbolicExpressionTreeNode)f.Clone(), (ISymbolicExpressionTreeNode)g.Clone()); 91 var h = (ISymbolicExpressionTreeNode)branch.GetSubtree(i).Clone(); 92 var hPrime = Derive(h, variableName); 93 fgPrime = Sum(Product(fgPrime, h), Product(fg, hPrime)); 89 var gPrime = Derive(g, variableName); 90 var fgPrime = Sum(Product(fprime, g), Product(gPrime, f)); 91 // prepare for next iteration 92 f = fg; 93 fprime = fgPrime; 94 94 } 95 return f gPrime;95 return fprime; 96 96 } else 97 97 // multiplication with only one argument has no effect -> derive the argument -
trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/DeriveTest.cs
r16565 r16737 65 65 66 66 Assert.AreEqual("0", Derive("(a+b)/(x+SQR(x))", "y")); // df(a,b,x) / dy = 0 67 68 69 Assert.AreEqual("('a' * 'b' * 'c')", Derive("a*b*c*d", "d")); 70 Assert.AreEqual("('a' / ('b' * 'c' * SQR('d') * (-1)))", Derive("a/b/c/d", "d")); 67 71 68 72 {
Note: See TracChangeset
for help on using the changeset viewer.