Changeset 16737


Ignore:
Timestamp:
04/01/19 19:15:54 (3 months ago)
Author:
gkronber
Message:

#2948: fixed a bug for products with >2 factors

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/DerivativeCalculator.cs

    r16565 r16737  
    8383        if (branch.SubtreeCount >= 2) {
    8484          var f = (ISymbolicExpressionTreeNode)branch.GetSubtree(0).Clone();
    85           var g = (ISymbolicExpressionTreeNode)branch.GetSubtree(1).Clone();
    8685          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();
    9088            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;
    9494          }
    95           return fgPrime;
     95          return fprime;
    9696        } else
    9797          // multiplication with only one argument has no effect -> derive the argument
  • trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/DeriveTest.cs

    r16565 r16737  
    6565
    6666      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"));
    6771
    6872      {
Note: See TracChangeset for help on using the changeset viewer.