File: intervalArithmetic.mac

package info (click to toggle)
maxima 5.42.1-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 150,192 kB
  • sloc: lisp: 382,565; fortran: 14,666; perl: 14,365; tcl: 11,123; sh: 4,622; makefile: 2,688; ansic: 444; xml: 23; awk: 17; sed: 17
file content (64 lines) | stat: -rw-r--r-- 1,759 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* ------------------------------------------------------------------- */
/* SARAG - Interval Arithmetic                                         */
/* by Fabrizio Caruso                                                  */


intervalProduct(lhs,rhs) :=
  [min(lhs[1]*rhs[1],lhs[1]*rhs[2],
       lhs[2]*rhs[1],lhs[2]*rhs[2]),
   max(lhs[1]*rhs[1],lhs[1]*rhs[2],
       lhs[2]*rhs[1],lhs[2]*rhs[2])];


squaredIntervalAt(interval) :=
  squaredIntervalAtAux(interval[1],interval[2]);

squaredIntervalAtAux(leftEnd,rightEnd) :=
  if leftEnd*rightEnd<1 then
    [0,max(leftEnd^2,rightEnd^2)]
  else
    [min(leftEnd^2,rightEnd^2),max(leftEnd^2,rightEnd^2)];


powerIntervalAt(interval,p) :=
  if oddp(p) then
     [interval[1]^p,interval[2]^p]
  else
     if interval[1]*interval[2]<1 then
         [0,max(interval[1],interval[2])^p]
     else
        if interval[1]>0 then
          [interval[1]^p,interval[2]^p]
        else
          [interval[2]^p,interval[1]^p];


constantByInterval(c,interval) :=
  if c = 0 then 
    [0]
  else
    if c>0 then
      [c*interval[1],c*interval[2]]
    else
      [c*interval[2],c*interval[1]];

constantPlusInterval(d,interval) :=
  [interval[1]+d,interval[2]+d];

evaluatePolAt(pol,var,interval) :=
  if degree(pol,var) < 1 then
    [pol]
  else
    evaluatePolAtAux(rest(reverse(poly2list(pol,var)),1),
                     constantByInterval(coeff(pol,var,degree(pol,var)),interval));

evaluatePolAtAux(revCoeffSeq,interval) := 
  if revCoeffSeq=[] then
    interval
  else
    evaluatePolAtAux(rest(revCoeffSeq,1),
                     constantPlusInterval(first(revCoeffSeq),
                                          interval)
                    );

0;