Free cookie consent management tool by TermsFeed Policy Generator

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

#2994: another unit test, smaller fixes and checks for invalid parameters

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2994-AutoDiffForIntervals/Tests/AutoDiffTest.cs

    r16727 r16738  
    189189      }
    190190
     191      {
     192
     193        // derivatives and intervals for flow psi problem
     194        var intervals = new Dictionary<string, Interval>();
     195        intervals.Add("x1", new Interval(60.0, 65.0));
     196        intervals.Add("x2", new Interval(30.0, 40.0));
     197        intervals.Add("x3", new Interval(5.0, 10.0));
     198        intervals.Add("x4", new Interval(0.5, 0.8));
     199        intervals.Add("x5", new Interval(0.2, 0.5));
     200
     201        var parser = new InfixExpressionParser();
     202        var formatter = new InfixExpressionFormatter();
     203
     204        var expr = parser.Parse("x1*x2*x5*(1 - sqr(x4/x5)) + x3 * log(x5/x4)");
     205
     206        var dfdx1 = DerivativeCalculator.Derive(expr, "x1");
     207        Assert.AreEqual("('x2' * 'x5' * ((SQR(('x4' / 'x5')) * (-1)) + 1))", formatter.Format(dfdx1));
     208        // x2 x5 (1 - sqr(x4/x5))
     209
     210        var dfdx2 = DerivativeCalculator.Derive(expr, "x2");
     211        Assert.AreEqual("('x1' * 'x5' * ((SQR(('x4' / 'x5')) * (-1)) + 1))", formatter.Format(dfdx2));
     212        // x1 x5 (1 - sqr(x4/x5))
     213
     214        var dfdx3 = DerivativeCalculator.Derive(expr, "x3");
     215        Assert.AreEqual("LOG(('x5' / 'x4'))", formatter.Format(dfdx3));
     216        // log(x5/x4)
     217
     218        var dfdx4 = DerivativeCalculator.Derive(expr, "x4");
     219        Assert.AreEqual("((('x1' * 'x2' * 'x5' * 'x4' * 2) / ('x5' * (-1*'x5'))) + (('x4' * 'x5' * 'x3') / ('x5' * SQR('x4') * (-1))))", formatter.Format(dfdx4));
     220        // -2*x1*x2*x5*x4/x5*1/x5 + x3*1/(x5/x4)*x5/sqr(x4)
     221
     222        var dfdx5 = DerivativeCalculator.Derive(expr, "x5");
     223        Assert.AreEqual("((('x4' * 'x3') / ('x5' * 'x4')) + ('x1' * 'x2' * ((SQR(('x4' / 'x5')) * (-1)) + 1)) + (('x1' * 'x2' * 'x5' * ('x4' * 'x4') * 2) / ('x5' * SQR('x5') * 1)))", formatter.Format(dfdx5));
     224      }
     225
     226
    191227    }
    192228  }
Note: See TracChangeset for help on using the changeset viewer.