fnsincosintrv.gms : Test sin/cos func/grad interval evals

Description

Test interval evaluators for sin and cos: function and gradient.
The test is designed to catch all the interesting combinations of
extreme points and inflection points so the implementation gets a full
workout.

Contributor: Steve, Jan 2017


Small Model of Type : GAMS


Category : GAMS Test library


Main file : fnsincosintrv.gms

$TITLE 'Test sin/cos func/grad interval evals' (FNSINCOSINTRV,SEQ=714)

$ontext
Test interval evaluators for sin and cos: function and gradient.
The test is designed to catch all the interesting combinations of
extreme points and inflection points so the implementation gets a full
workout.

Contributor: Steve, Jan 2017
$offtext

sets
  t 'tests cases' / t11*t14, t21*t24, t31*t34, t41*t44 /
  v 'values' /
    xlo
    xup
    flo_
    fup_
    glo_
    gup_
    flo
    fup
    glo
    gup
    flod
    fupd
    glod
    gupd
  /;
parameters
  eflo(t)  'errors in flo'
  efup(t)  'errors in fup'
  eglo(t)  'errors in glo'
  egup(t)  'errors in gup'
  ;
file fp /''/;  put fp;


table s(t,v) 'sin test data'
        xlo     xup     flo_    fup_    glo_    gup_
t11   [-1/6]   [ 2/6]                            1.0
t12   [-1/6]   [ 5/6]            1.0             1.0
t13   [-1/6]   [ 8/6]            1.0    -1.0     1.0
t14   [-1/6]   [11/6]   -1.0     1.0    -1.0     1.0

t21    [2/6]   [ 5/6]            1.0
t22    [2/6]   [ 8/6]            1.0    -1.0
t23    [2/6]   [11/6]   -1.0     1.0    -1.0
t24    [2/6]   [14/6]   -1.0     1.0    -1.0     1.0

t31    [5/6]   [ 8/6]                   -1.0
t32    [5/6]   [11/6]   -1.0            -1.0
t33    [5/6]   [14/6]   -1.0            -1.0     1.0
t34    [5/6]   [17/6]   -1.0     1.0    -1.0     1.0

t41    [8/6]   [11/6]   -1.0
t42    [8/6]   [14/6]   -1.0                     1.0
t43    [8/6]   [17/6]   -1.0     1.0             1.0
t44    [8/6]   [20/6]   -1.0     1.0    -1.0     1.0
;
s(t,'xlo') = s(t,'xlo') * pi;
s(t,'xup') = s(t,'xup') * pi;

s('t11','flo_') = sin(s('t11','xlo'));
s('t11','fup_') = sin(s('t11','xup'));
s('t11','glo_') = cos(s('t11','xup'));

s('t12','flo_') = sin(s('t12','xlo'));
s('t12','glo_') = cos(s('t12','xup'));

s('t13','flo_') = sin(s('t13','xup'));

s('t21','flo_') = sin(s('t21','xup'));
s('t21','glo_') = cos(s('t21','xup'));
s('t21','gup_') = cos(s('t21','xlo'));

s('t22','flo_') = sin(s('t22','xup'));
s('t22','gup_') = cos(s('t22','xlo'));

s('t23','gup_') = cos(s('t23','xup'));

s('t31','flo_') = sin(s('t31','xup'));
s('t31','fup_') = sin(s('t31','xlo'));
s('t31','gup_') = cos(s('t31','xup'));

s('t32','fup_') = sin(s('t32','xlo'));
s('t32','gup_') = cos(s('t32','xup'));

s('t33','fup_') = sin(s('t33','xup'));

s('t41','fup_') = sin(s('t41','xup'));
s('t41','glo_') = cos(s('t41','xlo'));
s('t41','gup_') = cos(s('t41','xup'));

s('t42','fup_') = sin(s('t42','xup'));
s('t42','glo_') = cos(s('t42','xlo'));

s('t43','glo_') = cos(s('t43','xup'));

s(t,'flo') = sin.low  (s(t,'xlo'):s(t,'xup'));
s(t,'fup') = sin.high (s(t,'xlo'):s(t,'xup'));
s(t,'glo') = sin.gradL(s(t,'xlo'):s(t,'xup'));
s(t,'gup') = sin.gradH(s(t,'xlo'):s(t,'xup'));
s(t,'flod') = s(t,'flo') - s(t,'flo_');
s(t,'fupd') = s(t,'fup') - s(t,'fup_');
s(t,'glod') = s(t,'glo') - s(t,'glo_');
s(t,'gupd') = s(t,'gup') - s(t,'gup_');

eflo(t) = round(abs(s(t,'flod')),12);
efup(t) = round(abs(s(t,'fupd')),12);
eglo(t) = round(abs(s(t,'glod')),12);
egup(t) = round(abs(s(t,'gupd')),12);

if {[card(eflo)+card(efup)+card(eglo)+card(egup)] > 0,
  execute_unload 'stResults';
  execute_unload 'stErrs', eflo, efup, eglo, egup;
  putclose ' ' / '** SINE ERRORS FOUND **'/' '/;
  abort$1 'aborting';
};


* ------------------------------------------------------

table c(t,v) 'cos test data'
        xlo     xup     flo_    fup_    glo_    gup_
t11   [-1/6]   [ 2/6]            1.0
t12   [-1/6]   [ 5/6]            1.0    -1.0
t13   [-1/6]   [ 8/6]   -1.0     1.0    -1.0
t14   [-1/6]   [11/6]   -1.0     1.0    -1.0     1.0

t21    [2/6]   [ 5/6]                   -1.0
t22    [2/6]   [ 8/6]   -1.0            -1.0
t23    [2/6]   [11/6]   -1.0            -1.0     1.0
t24    [2/6]   [14/6]   -1.0     1.0    -1.0     1.0

t31    [5/6]   [ 8/6]   -1.0
t32    [5/6]   [11/6]   -1.0                     1.0
t33    [5/6]   [14/6]   -1.0     1.0             1.0
t34    [5/6]   [17/6]   -1.0     1.0    -1.0     1.0

t41    [8/6]   [11/6]                            1.0
t42    [8/6]   [14/6]            1.0             1.0
t43    [8/6]   [17/6]            1.0    -1.0     1.0
t44    [8/6]   [20/6]   -1.0     1.0    -1.0     1.0
;
c(t,'xlo') = c(t,'xlo') * pi;
c(t,'xup') = c(t,'xup') * pi;

c('t11','flo_') =  cos(c('t11','xup'));
c('t11','glo_') = -sin(c('t11','xup'));
c('t11','gup_') = -sin(c('t11','xlo'));

c('t12','flo_') =  cos(c('t12','xup'));
c('t12','gup_') = -sin(c('t12','xlo'));

c('t13','gup_') = -sin(c('t13','xup'));

c('t21','flo_') =  cos(c('t21','xup'));
c('t21','fup_') =  cos(c('t21','xlo'));
c('t21','gup_') = -sin(c('t21','xup'));

c('t22','fup_') =  cos(c('t22','xlo'));
c('t22','gup_') = -sin(c('t22','xup'));

c('t23','fup_') =  cos(c('t23','xup'));

c('t31','fup_') =  cos(c('t31','xup'));
c('t31','glo_') = -sin(c('t31','xlo'));
c('t31','gup_') = -sin(c('t31','xup'));

c('t32','fup_') =  cos(c('t32','xup'));
c('t32','glo_') = -sin(c('t32','xlo'));

c('t33','glo_') = -sin(c('t33','xup'));

c('t41','flo_') =  cos(c('t41','xlo'));
c('t41','fup_') =  cos(c('t41','xup'));
c('t41','glo_') = -sin(c('t41','xup'));

c('t42','flo_') =  cos(c('t42','xlo'));
c('t42','glo_') = -sin(c('t42','xup'));

c('t43','flo_') =  cos(c('t43','xup'));


c(t,'flo') = cos.low  (c(t,'xlo'):c(t,'xup'));
c(t,'fup') = cos.high (c(t,'xlo'):c(t,'xup'));
c(t,'glo') = cos.gradL(c(t,'xlo'):c(t,'xup'));
c(t,'gup') = cos.gradH(c(t,'xlo'):c(t,'xup'));
c(t,'flod') = c(t,'flo') - c(t,'flo_');
c(t,'fupd') = c(t,'fup') - c(t,'fup_');
c(t,'glod') = c(t,'glo') - c(t,'glo_');
c(t,'gupd') = c(t,'gup') - c(t,'gup_');

eflo(t) = round(abs(c(t,'flod')),12);
efup(t) = round(abs(c(t,'fupd')),12);
eglo(t) = round(abs(c(t,'glod')),12);
egup(t) = round(abs(c(t,'gupd')),12);

if {[card(eflo)+card(efup)+card(eglo)+card(egup)] > 0,
  execute_unload 'ctResults';
  execute_unload 'ctErrs', eflo, efup, eglo, egup;
  putclose ' ' / '** COSINE ERRORS FOUND **'/' '/;
  abort$1 'aborting';
else
  putclose ' ' / '** TEST OK **'/' '/;
};