Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/01/19 19:15:54 (6 years ago)
Author:
gkronber
Message:

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

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.