00001 #ifndef __ISLOPE_H__
00002 #define __ISLOPE_H__
00003
00004 #include "interval.h"
00005 #include <stdlib.h>
00006 #include <iostream>
00007
00008 using namespace coco;
00009
00010 typedef interval I;
00011
00012
00014
00015
00016 class Islope
00017 {
00018 private:
00020 I *data;
00021
00022 public:
00024 int order;
00026 double *minmaxval;
00028 inline Islope(void);
00030 inline Islope(int n);
00032 inline Islope(double a,int n);
00034 inline Islope(double a, double b, int n);
00036 inline Islope(const Islope &a);
00038 virtual ~Islope();
00040 inline Islope& operator=(const Islope &a);
00041
00042 inline I& operator[] (int pos) const;
00044 inline static Islope getVar(const double &x,int n);
00046 inline static Islope getVar(const double &x, const double &y, int n);
00048 inline static Islope getVar(const I &x, int n);
00050 inline static Islope getVar(const double &x, const double &y, const double &z, int n);
00052 inline void setDeg(int n);
00053 };
00054
00055
00057 inline Islope operator +(const Islope &a, const Islope &b);
00059 inline Islope operator +(const double &a, const Islope &b);
00061 inline Islope operator +(const Islope &a, const double &b);
00063 inline Islope operator -(const Islope &a, const Islope &b);
00065 inline Islope operator -(const double &a, const Islope &b);
00067 inline Islope operator -(const Islope &a, const double &b);
00069 inline Islope operator -(const Islope &a);
00071 inline Islope operator *(const Islope &a, const Islope &b);
00073 inline Islope operator *(const double &a, const Islope &b);
00075 inline Islope operator *(const Islope &a, const double &b);
00077 inline Islope operator /(const Islope &a, const Islope &b);
00079 inline Islope operator /(const double &a, const Islope &b);
00081 inline Islope operator /(const Islope &a, const double &b);
00082
00083
00087 std::ostream &operator << (std::ostream &s, const Islope &a);
00088
00089
00091 inline Islope exp(const Islope &a);
00093 inline Islope sin(const Islope &a);
00095 inline Islope cos(const Islope &a);
00097 inline Islope sqrt(const Islope &a);
00099 inline Islope power(const Islope &a, int n);
00101 inline Islope log(const Islope &a);
00103 inline Islope atan(const Islope &a);
00105 inline Islope atan2(const Islope &a, const Islope &b);
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 inline Islope::Islope(void)
00116 {
00117 order=1;
00118 data= new I[3];
00119 data[0] = I(0.);
00120 data[1] = I(0.);
00121 data[2] = I(0.);
00122 minmaxval= new double[2];
00123 minmaxval[0] = 0.;
00124 minmaxval[1] = 0.;
00125
00126 }
00127
00128 inline Islope::Islope(int n)
00129 {
00130 if ((n!=2)&&(n!=1)){
00131 std::cerr<<"Islope(double,int) is for initializing slope of order 1 or 2 ";
00132 abort();
00133 }
00134 else if(n==1){
00135 order=1;
00136 data= new I[3];
00137 data[0] = I(0.);
00138 data[1] = I(0.);
00139 data[2] = I(0.);
00140 minmaxval= new double[2];
00141 minmaxval[0] = 0.;
00142 minmaxval[1] = 0.;
00143 }
00144 else if(n==2){
00145 order=2;
00146 data= new I[7];
00147 data[0] = I(0.);
00148 data[1] = I(0.);
00149 data[2] = I(0.);
00150 data[3] = I(0.);
00151 data[4] = I(0.);
00152 data[5] = I(0.);
00153 data[6] = I(0.);
00154 minmaxval= new double[2];
00155 minmaxval[0] = 0.;
00156 minmaxval[1] = 0.;
00157 }
00158 }
00159
00160 inline Islope::Islope(double a, int n)
00161 {
00162 if ((n!=2)&&(n!=1)){
00163 std::cerr<<"Islope(double,int) is for initializing slope of order 1 or 2 ";
00164 abort();
00165 }
00166 else if(n==1){
00167 order=1;
00168 data= new I[3];
00169 data[0] = I(a);
00170 data[1] = I(a);
00171 data[2] = I(0.);
00172 minmaxval= new double[2];
00173 minmaxval[0] = a;
00174 minmaxval[1] = a;
00175 }
00176 else if(n==2){
00177 order=2;
00178 data= new I[7];
00179 data[0] = I(a);
00180 data[1] = I(a);
00181 data[2] = I(0.);
00182 data[3] = I(a);
00183 data[4] = I(0.);
00184 data[5] = I(0.);
00185 data[6] = I(0.);
00186 minmaxval= new double[2];
00187 minmaxval[0] = a;
00188 minmaxval[1] = a;
00189 }
00190 }
00191
00192
00193 inline Islope::Islope(double a, double b, int n)
00194 {
00195 if ((n!=2)&&(n!=1)){
00196 std::cerr<<"Islope(double,int) is for initializing slope of order 1 or 2 ";
00197 abort();
00198 }
00199 else if(n==1){
00200 order=1;
00201 data= new I[3];
00202 data[0] = I(a,b);
00203 data[1] = I((a+b)/2);
00204 data[2] = I(0.);
00205 minmaxval= new double[2];
00206 minmaxval[0] = a;
00207 minmaxval[1] = b;
00208 }
00209 else if(n==2){
00210 order=2;
00211 data= new I[7];
00212 data[0] = I(a,b);
00213 data[1] = I((a+b)/2);
00214 data[2] = I(0.);
00215 data[3] = I((a+b)/2);
00216 data[4] = I(0.);
00217 data[5] = I(0.);
00218 data[6] = I(0.);
00219 minmaxval= new double[2];
00220 minmaxval[0] = a;
00221 minmaxval[1] = b;
00222 }
00223 }
00224
00225 inline Islope::Islope(const Islope &d)
00226 {
00227 order = d.order;
00228 int _tmp=3;
00229 if (order==2) _tmp=7;
00230 data = new I[_tmp];
00231 minmaxval= new double[2];
00232 memcpy(data, d.data, (_tmp)*sizeof(I));
00233 memcpy(minmaxval, d.minmaxval, 2*sizeof(double));
00234 }
00235
00236 inline Islope& Islope::operator=(const Islope &a)
00237 {
00238 if (this != &a){
00239 if (data) delete [] data;
00240 if (a.order==1){
00241 data = new I[3];
00242 for (int i=0; i<3; i++)
00243 data[i]=a[i];
00244 }
00245 if (a.order==2){
00246 data = new I[7];
00247 for (int i=0; i<7; i++){
00248 data[i]=a[i];
00249 }
00250 }
00251 minmaxval[0]=a.minmaxval[0];
00252 minmaxval[1]=a.minmaxval[1];
00253 }
00254 return (*this);
00255 }
00256
00257
00258 inline I &Islope::operator[] (int pos) const
00259 {
00260 return data[pos];
00261 }
00262
00263
00264
00265
00266
00267 inline Islope Islope::getVar(const double &x, int n)
00268 {
00269 if ((n!=2)&&(n!=1)){
00270 std::cerr<<"Islope(double,int) is for initializing slope of order 1 or 2 ";
00271 abort();
00272 }
00273 Islope d;
00274 if(n==1){
00275 Islope c;
00276 c[0]=I(x);
00277 c[1]=I(x);
00278 c[2]=I(1.);
00279 c.minmaxval[0] = x;
00280 c.minmaxval[1] = x;
00281 d=c;
00282 }
00283 if(n==2){
00284 d.order=2;
00285 Islope c(2);
00286 c[0] = I(x);
00287 c[1] = I(x);
00288 c[2] = I(1.);
00289 c[3] = I(x);
00290 c[4] = I(1.);
00291 c[5] = I(0.);
00292 c[6] = I(x);
00293 c.minmaxval[0] = x;
00294 c.minmaxval[1] = x;
00295 d=c;
00296 }
00297 return d;
00298 }
00299
00300 inline Islope Islope::getVar(const double &x, const double &y, int n)
00301 {
00302 if ((n!=2)&&(n!=1)){
00303 std::cerr<<"Islope(double,int) is for initializing slope of order 1 or 2 ";
00304 abort();
00305 }
00306 Islope d;
00307 if(n==1){
00308 Islope c;
00309 c[0]=I(x,y);
00310 c[1]=I((x+y)/2);
00311 c[2]=I(1.);
00312 c.minmaxval[0] = x;
00313 c.minmaxval[1] = y;
00314 d=c;
00315 }
00316 if (n==2){
00317 d.order=2;
00318 Islope c(2);
00319 c[0] = I(x,y);
00320 c[1] = I((x+y)/2);
00321 c[2] = I(1.);
00322 c[3] = I((x+y)/2);
00323 c[4] = I(1.);
00324 c[5] = I(0.);
00325 c[6] = I(x,y);
00326 c.minmaxval[0] = x;
00327 c.minmaxval[1] = y;
00328 d=c;
00329 }
00330 return d;
00331 }
00332
00333 inline Islope Islope::getVar(const I &x, int n)
00334 {
00335 if ((n!=2)&&(n!=1)){
00336 std::cerr<<"Islope(double,int) is for initializing slope of order 1 or 2 ";
00337 abort();
00338 }
00339 Islope d;
00340 if(n==1){
00341 Islope c;
00342 c[0]=x;
00343 c[1]=I((x.inf()+x.sup())/2);
00344 c[2]=I(1.);
00345 c.minmaxval[0] = x.inf();
00346 c.minmaxval[1] = x.sup();
00347 d=c;
00348 }
00349 if (n==2){
00350 d.order=2;
00351 Islope c(2);
00352 c[0] = x;
00353 c[1] = I((x.inf()+x.sup())/2);
00354 c[2] = I(1.);
00355 c[3] = I((x.inf()+x.sup())/2);
00356 c[4] = I(1.);
00357 c[5] = I(0.);
00358 c[6] = x;
00359 c.minmaxval[0] = x.inf();
00360 c.minmaxval[1] = x.sup();
00361 d=c;
00362 }
00363 return d;
00364 }
00365
00366 inline Islope Islope::getVar(const double &x, const double &y, const double &z, int n)
00367 {
00368 if ((n!=2)&&(n!=1)){
00369 std::cerr<<"Islope(double,int) is for initializing slope of order 1 or 2 ";
00370 abort();
00371 }
00372 Islope d;
00373 if(n==1){
00374 Islope c;
00375 c[0]=I(x,y);
00376 c[1]=I(z);
00377 c[2]=I(1.);
00378 c.minmaxval[0] = x;
00379 c.minmaxval[1] = y;
00380 d=c;
00381 }
00382 if (n==2){
00383 d.order=2;
00384 Islope c(2);
00385 c[0] = I(x,y);
00386 c[1] = I(z);
00387 c[2] = I(1.);
00388 c[3] = I(z);
00389 c[4] = I(1.);
00390 c[5] = I(0.);
00391 c[6] = I(x,y);
00392 c.minmaxval[0] = x;
00393 c.minmaxval[1] = y;
00394 d=c;
00395 }
00396 return d;
00397 }
00398
00399 inline void Islope::setDeg(int n)
00400 {
00401 I tmp[7];
00402 if ((n==1)&&(order==2)){
00403 for (int i=0; i<3; i++)
00404 tmp[i]=data[i];
00405 delete [] data;
00406 data=new I[3];
00407 for (int i=0; i<3; i++)
00408 data[i]=tmp[i];
00409 }
00410 if ((n==2)&&(order==1)) {
00411 for (int i=0; i<3; i++)
00412 tmp[i]=data[i];
00413 delete [] data;
00414 data=new I[7];
00415 for (int i=0; i<3; i++)
00416 data[i]=tmp[i];
00417 for (int j=3; j<7; j++)
00418 data[j]=0.;
00419 }
00420 order=n;
00421 }
00422
00423
00424
00425 inline Islope operator +(const Islope &a, const Islope &b)
00426 {
00427 if (a.order!=b.order){
00428 std::cerr<<"+ slope order should be the same";
00429 abort();
00430 }
00431 Islope d;
00432 if (a.order==1){
00433 Islope c;
00434 c[0]=a[0]+b[0];
00435 c[1]=a[1]+b[1];
00436 c[2]=a[2]+b[2];
00437 d=c;
00438 }
00439 if (a.order==2){
00440 Islope c(2);
00441 d.order=2;
00442 c[0]=a[0]+b[0];
00443 c[1]=a[1]+b[1];
00444 c[2]=a[2]+b[2];
00445 c[3]=a[3]+b[3];
00446 c[4]=a[4]+b[4];
00447 c[5]=a[5]+b[5];
00448 if ((a[6].inf()==0) && (a[6].sup()==0)){
00449 c[6]=b[6];
00450 }
00451 else {
00452 c[6]=a[6];
00453 }
00454 c.minmaxval[0]=a.minmaxval[0]+b.minmaxval[0];
00455 c.minmaxval[1]=a.minmaxval[1]+b.minmaxval[1];
00456 d=c;
00457 }
00458 return d;
00459 }
00460
00461 inline Islope operator +(const double &a, const Islope &b)
00462 {
00463 Islope d;
00464 if (b.order==1){
00465 Islope c;
00466 c[0]=I(a)+b[0];
00467 c[1]=I(a)+b[1];
00468 c[2]=b[2];
00469 d=c;
00470 }
00471 if (b.order==2){
00472 Islope c(2);
00473 d.order=2;
00474 c[0]=I(a)+b[0];
00475 c[1]=I(a)+b[1];
00476 c[2]=b[2];
00477 c[3]=I(a)+b[3];
00478 c[4]=b[4];
00479 c[5]=b[5];
00480 c[6]=b[6];
00481 c.minmaxval[0]=a+b.minmaxval[0];
00482 c.minmaxval[1]=a+b.minmaxval[1];
00483 d=c;
00484 }
00485 return d;
00486 }
00487
00488 inline Islope operator +(const Islope &a, const double &b)
00489 {
00490 Islope d;
00491 if (a.order==1){
00492 Islope c;
00493 c[0]=a[0]+I(b);
00494 c[1]=a[1]+I(b);
00495 c[2]=a[2];
00496 d=c;
00497 }
00498 if (a.order==2){
00499 Islope c(2);
00500 d.order=2;
00501 c[0]=a[0]+I(b);
00502 c[1]=a[1]+I(b);
00503 c[2]=a[2];
00504 c[3]=a[3]+I(b);
00505 c[4]=a[4];
00506 c[5]=a[5];
00507 c[6]=a[6];
00508 c.minmaxval[0]=a.minmaxval[0]+b;
00509 c.minmaxval[1]=a.minmaxval[1]+b;
00510 d=c;
00511 }
00512 return d;
00513 }
00514
00515 inline Islope operator -(const Islope &a, const Islope &b)
00516 {
00517 if (a.order!=b.order){
00518 std::cerr<<"+ slope order should be the same";
00519 abort();
00520 }
00521 Islope d;
00522 if (a.order==1){
00523 Islope c;
00524 c[0]=a[0]-b[0];
00525 c[1]=a[1]-b[1];
00526 c[2]=a[2]-b[2];
00527 d=c;
00528 }
00529 if (a.order==2){
00530 Islope c(2);
00531 d.order=2;
00532 c[0]=a[0]-b[0];
00533 c[1]=a[1]-b[1];
00534 c[2]=a[2]-b[2];
00535 c[3]=a[3]-b[3];
00536 c[4]=a[4]-b[4];
00537 c[5]=a[5]-b[5];
00538 if ((a[6].inf()==0) && (a[6].sup()==0)){
00539 c[6]=b[6];
00540 }
00541 else {
00542 c[6]=a[6];
00543 }
00544 c.minmaxval[0]=a.minmaxval[0]-b.minmaxval[0];
00545 c.minmaxval[1]=a.minmaxval[1]-b.minmaxval[1];
00546 d=c;
00547 }
00548 return d;
00549 }
00550
00551 inline Islope operator -(const double &a, const Islope &b)
00552 {
00553 Islope d;
00554 if (b.order==1){
00555 Islope c;
00556 c[0]=I(a)-b[0];
00557 c[1]=I(a)-b[1];
00558 c[2]=-b[2];
00559 d=c;
00560 }
00561 if (b.order==2){
00562 Islope c(2);
00563 d.order=2;
00564 c[0]=I(a)-b[0];
00565 c[1]=I(a)-b[1];
00566 c[2]=-b[2];
00567 c[3]=I(a)-b[3];
00568 c[4]=-b[4];
00569 c[5]=-b[5];
00570 c[6]=b[6];
00571 c.minmaxval[0]=a-b.minmaxval[0];
00572 c.minmaxval[1]=a-b.minmaxval[1];
00573 d=c;
00574 }
00575 return d;
00576 }
00577
00578 inline Islope operator -(const Islope &a, const double &b)
00579 {
00580 Islope d;
00581 if (a.order==1){
00582 Islope c;
00583 c[0]=a[0]-I(b);
00584 c[1]=a[1]-I(b);
00585 c[2]=a[2];
00586 d=c;
00587 }
00588 if (a.order==2){
00589 Islope c(2);
00590 d.order=2;
00591 c[0]=a[0]-I(b);
00592 c[1]=a[1]-I(b);
00593 c[2]=a[2];
00594 c[3]=a[3]-I(b);
00595 c[4]=a[4];
00596 c[5]=a[5];
00597 c[6]=a[6];
00598 c.minmaxval[0]=a.minmaxval[0]+b;
00599 c.minmaxval[1]=a.minmaxval[1]+b;
00600 d=c;
00601 }
00602 return d;
00603 }
00604
00605 inline Islope operator -(const Islope &a)
00606 {
00607 Islope d;
00608 if (a.order==1){
00609 Islope c;
00610 c[0]=-a[0];
00611 c[1]=-a[1];
00612 c[2]=-a[2];
00613 d=c;
00614 }
00615 if (a.order==2){
00616 Islope c(2);
00617 d.order=2;
00618 c[0]=-a[0];
00619 c[1]=-a[1];
00620 c[2]=-a[2];
00621 c[3]=-a[3];
00622 c[4]=-a[4];
00623 c[5]=-a[5];
00624 c[6]=a[6];
00625 c.minmaxval[0]=-a.minmaxval[0];
00626 c.minmaxval[1]=-a.minmaxval[1];
00627 d=c;
00628 }
00629 return d;
00630 }
00631
00632 inline Islope operator *(const Islope &a, const Islope &b)
00633 {
00634 if (a.order!=b.order){
00635 std::cerr<<"* slope order should be the same";
00636 abort();
00637 }
00638 Islope d;
00639 if (a.order==1){
00640 Islope c;
00641 c[0]=a[0]*b[0];
00642 c[1]=a[1]*b[1];
00643 c[2]=a[2]*b[1]+a[0]*b[2];
00644 d=c;
00645 }
00646 if (a.order==2){
00647 Islope c(2);
00648 d.order=2;
00649 c[0]=a[0]*b[0];
00650 c[1]=a[1]*b[1];
00651 c[2]=a[2]*b[1]+a[0]*b[2];
00652 c[3]=a[3]*b[3];
00653 c[4]=a[4]*b[1]+a[1]*b[4];
00654 c[5]=a[5]*b[1]+a[2]*b[2]+a[3]*b[5];
00655 if ((a[6].inf()==0) && (a[6].sup()==0)){
00656 c[6]=b[6];
00657 }
00658 else {
00659 c[6]=a[6];
00660 }
00661 c.minmaxval[0]=a.minmaxval[0]*b.minmaxval[0];
00662 c.minmaxval[1]=a.minmaxval[1]*b.minmaxval[1];
00663 d=c;
00664 }
00665 return d;
00666 }
00667
00668 inline Islope operator *(const double &a, const Islope &b)
00669 {
00670 Islope d;
00671 if (b.order==1){
00672 Islope c;
00673 c[0]=I(a)*b[0];
00674 c[1]=I(a)*b[1];
00675 c[2]=I(a)*b[2];
00676 d=c;
00677 }
00678 if (b.order==2){
00679 Islope c(2);
00680 d.order=2;
00681 c[0]=I(a)*b[0];
00682 c[1]=I(a)*b[1];
00683 c[2]=I(a)*b[2];
00684 c[3]=I(a)*b[3];
00685 c[4]=I(a)*b[4];
00686 c[5]=I(a)*b[5];
00687 c[6]=b[6];
00688 c.minmaxval[0]=a*b.minmaxval[0];
00689 c.minmaxval[1]=a*b.minmaxval[1];
00690 d=c;
00691 }
00692 return d;
00693 }
00694
00695 inline Islope operator *(const Islope &a, const double &b)
00696 {
00697 Islope d;
00698 if (a.order==1){
00699 Islope c;
00700 c[0]=I(b)*a[0];
00701 c[1]=I(b)*a[1];
00702 c[2]=I(b)*a[2];
00703 d=c;
00704 }
00705 if (a.order==2){
00706 Islope c(2);
00707 d.order=2;
00708 c[0]=I(b)*a[0];
00709 c[1]=I(b)*a[1];
00710 c[2]=I(b)*a[2];
00711 c[3]=I(b)*a[3];
00712 c[4]=I(b)*a[4];
00713 c[5]=I(b)*a[5];
00714 c[6]=a[6];
00715 c.minmaxval[0]=a.minmaxval[0]*b;
00716 c.minmaxval[1]=a.minmaxval[1]*b;
00717 d=c;
00718 }
00719 return d;
00720 }
00721
00722 inline Islope operator /(const double &a, const Islope &b)
00723 {
00724 Islope d;
00725 if (b.order==1){
00726 Islope c(a,1);
00727 d=c/b;
00728 }
00729 if (b.order==2){
00730 Islope c(a,2);
00731 d.order=2;
00732 d=c/b;
00733 }
00734 return d;
00735 }
00736
00737 inline Islope operator /(const Islope &a, const Islope &b)
00738 {
00739 Islope d;
00740 if (a.order==1){
00741 Islope c;
00742 c[0]=a[0]/b[0];
00743 c[1]=a[1]/b[1];
00744 c[2]=(a[2]-c[1]*b[2])/b[0];
00745 d=c;
00746 }
00747 if (a.order==2){
00748 Islope c(2);
00749 d.order=2;
00750 c[0]=a[0]/b[0];
00751 c[1]=a[1]/b[1];
00752 c[2]=(a[2]-c[1]*b[2])/b[0];
00753 c[3]=a[3]/b[3];
00754 c[4]=(a[4]*b[1]-a[1]*b[4])/power(b[1],2);
00755 c[5]=a[5]/b[0]-c[1]*b[5]/b[0]+(c[1]*b[2]*(b[2]-a[2]))/(b[0]*b[3]);
00756 if ((a[6].inf()==0) && (a[6].sup()==0)){
00757 c[6]=b[6];
00758 }
00759 else {
00760 c[6]=a[6];
00761 }
00762 c.minmaxval[0]=a.minmaxval[0]/b.minmaxval[0];
00763 c.minmaxval[1]=a.minmaxval[1]/b.minmaxval[1];
00764 d=c;
00765 }
00766 return d;
00767 }
00768
00769 inline Islope operator /(const Islope &a, const double &b)
00770 {
00771 Islope d;
00772 if (a.order==1){
00773 Islope c;
00774 c[0]=a[0]/I(b);
00775 c[1]=a[1]/I(b);
00776 c[2]=a[2]/I(b);
00777 d=c;
00778 }
00779 if (a.order==2){
00780 Islope c(2);
00781 d.order=2;
00782 c[0]=a[0]/I(b);
00783 c[1]=a[1]/I(b);
00784 c[2]=a[2]/I(b);
00785 c[3]=a[3]/I(b);
00786 c[4]=a[4]/I(b);
00787 c[5]=a[5]/I(b);
00788 c[6]=a[6];
00789 c.minmaxval[0]=a.minmaxval[0]/b;
00790 c.minmaxval[1]=a.minmaxval[1]/b;
00791 d=c;
00792 }
00793 return d;
00794 }
00795
00796 inline Islope exp(const Islope &a)
00797 {
00798 Islope d;
00799 if (a.order==1){
00800 Islope c;
00801 c[0]=exp(a[0]);
00802 c[1]=exp(a[1]);
00803 double lowdiff=a[0].inf()-a[1].inf();
00804 double supdiff=a[0].sup()-a[1].sup();
00805 if ((lowdiff==0)&&(supdiff==0)){
00806 c[2]=c[0]*a[2];
00807 }
00808 if ((lowdiff!=0)&&(supdiff!=0)){
00809 double low=(exp(a[0].inf())-exp(a[1].inf()))/lowdiff;
00810 double sup=(exp(a[0].sup())-exp(a[1].sup()))/supdiff;
00811 c[2]=I(low,sup)*a[2];
00812 }
00813 if ((lowdiff==0)&&(supdiff!=0)){
00814 double low=exp(a[0].inf());
00815 double sup=(exp(a[0].sup())-exp(a[1].sup()))/supdiff;
00816 c[2]=I(low,sup)*a[2];
00817 }
00818 if ((lowdiff!=0)&&(supdiff==0)){
00819 double low=(exp(a[0].inf())-exp(a[1].inf()))/lowdiff;
00820 double sup=exp(a[0].sup());
00821 c[2]=I(low,sup)*a[2];
00822 }
00823 d=c;
00824 }
00825 if (a.order==2){
00826 Islope c(2);
00827 d.order=2;
00828 c[0]=exp(a[0]);
00829 c[1]=exp(a[1]);
00830 c[3]=exp(a[3]);
00831 c[6]=a[6];
00832 double lowdiff=a[0].inf()-a[1].inf();
00833 double supdiff=a[0].sup()-a[1].sup();
00834 if ((lowdiff==0)&&(supdiff==0)){
00835 c[2]=c[0]*a[2];
00836 c[4]=c[1]*a[4];
00837 c[5]=c[0]*(0.5*power(a[2],2)+a[5]);
00838 }
00839 if ((lowdiff!=0)&&(supdiff!=0)){
00840 double low=(exp(a[0].inf())-exp(a[1].inf()))/lowdiff;
00841 double sup=(exp(a[0].sup())-exp(a[1].sup()))/supdiff;
00842 c[2]=I(low,sup)*a[2];
00843 c[4]=c[1]*a[4];
00844 double low2=(low-c[1].inf())/lowdiff;
00845 double sup2=(sup-c[1].sup())/supdiff;
00846 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
00847 }
00848 if ((lowdiff==0)&&(supdiff!=0)){
00849 double low=exp(a[0].inf());
00850 double sup=(exp(a[0].sup())-exp(a[1].sup()))/supdiff;
00851 c[2]=I(low,sup)*a[2];
00852 c[4]=c[1]*a[4];
00853 double low2=0.5*exp(a[0].inf());
00854 double sup2=(sup-c[1].sup())/supdiff;
00855 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
00856 }
00857 if ((lowdiff!=0)&&(supdiff==0)){
00858 double low=(exp(a[0].inf())-exp(a[1].inf()))/lowdiff;
00859 double sup=exp(a[0].sup());
00860 c[2]=I(low,sup)*a[2];
00861 c[4]=c[1]*a[4];
00862 double low2=(low-c[1].inf())/lowdiff;
00863 double sup2=0.5*exp(a[0].sup());
00864 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
00865 }
00866 if (c[5].empty()){
00867 c[2]=c[0]*a[2];
00868 c[5]=c[0]*(0.5*power(a[2],2)+a[5]);
00869 }
00870 c.minmaxval[0]=exp(a.minmaxval[0]);
00871 c.minmaxval[1]=exp(a.minmaxval[1]);
00872 d=c;
00873 }
00874 return d;
00875 }
00876
00877 inline Islope sin(const Islope &a)
00878 {
00879 Islope d;
00880 double low;
00881 double sup;
00882 double low2;
00883 double sup2;
00884 double lowdiff;
00885 double supdiff;
00886
00887 if (a.order==1){
00888 Islope c;
00889 c[0]=sin(a[0]);
00890 c[0]=sin(a[0]);
00891 c[1]=sin(a[1]);
00892 if (width(a[0])>=U_PI){
00893 c[2]=cos(a[0])*a[2];
00894 }
00895
00896 else if ((c[0].inf()<=0) && (c[0].sup()<=0)){
00897 lowdiff=a[0].inf()-a[1].inf();
00898 supdiff=a[0].sup()-a[1].sup();
00899
00900 if (lowdiff!=0){
00901 low=(sin(a[0].inf())-sin(a[1].inf()))/lowdiff;
00902 }
00903 else {
00904 low=cos(a[0].inf());
00905 }
00906
00907 if (supdiff!=0){
00908 sup=(sin(a[0].sup())-sin(a[1].sup()))/supdiff;
00909 }
00910 else {
00911 sup=cos(a[0].sup());
00912 }
00913
00914 c[2]=I(low,sup)*a[2];
00915 }
00916
00917 else if ((c[0].inf()>=0) && (c[0].sup()>=0)){
00918 lowdiff=a[0].inf()-a[1].inf();
00919 supdiff=a[0].sup()-a[1].sup();
00920
00921 if (lowdiff!=0){
00922 sup=(sin(a[0].inf())-sin(a[1].inf()))/lowdiff;
00923 }
00924 else {
00925 sup=cos(a[0].inf());
00926 }
00927
00928 if (supdiff!=0){
00929 low=(sin(a[0].sup())-sin(a[1].sup()))/supdiff;
00930 }
00931 else {
00932 low=cos(a[0].sup());
00933 }
00934 c[2]=I(low,sup)*a[2];
00935 }
00936
00937 else {
00938 c[2]=cos(a[0])*a[2];
00939 }
00940
00941 d=c;
00942 }
00943
00944 if (a.order==2){
00945 Islope c(2);
00946 d.order=2;
00947 c[0]=sin(a[0]);
00948 c[0]=sin(a[0]);
00949 c[1]=sin(a[1]);
00950 c[3]=sin(a[3]);
00951 c[4]=cos(a[1])*a[4];
00952 c[6]=a[6];
00953 I tmp=cos(a[0]);
00954 if (width(a[0])>=U_PI/2.){
00955 c[2]=cos(a[0])*a[2];
00956 c[5]=0.5*(-sin(a[0])*power(a[2],2))+cos(a[0])*a[5];
00957 }
00958
00959 else if ((c[0].inf()>=0) && (c[0].sup()>=0) && (tmp.inf()>=0) && (tmp.sup()>=0)){
00960 lowdiff=a[0].inf()-a[1].inf();
00961 supdiff=a[0].sup()-a[1].sup();
00962
00963 if (lowdiff!=0){
00964 sup=(sin(a[0].inf())-sin(a[1].inf()))/lowdiff;
00965 sup2=(sup-cos(a[1].inf()))/lowdiff;
00966 }
00967 else {
00968 sup=cos(a[0].inf());
00969 sup2=-0.5*c[0].inf();
00970 }
00971
00972 if (supdiff!=0){
00973 low=(sin(a[0].sup())-sin(a[1].sup()))/supdiff;
00974 low2=(low-cos(a[1].sup()))/supdiff;
00975 }
00976 else {
00977 low=cos(a[0].sup());
00978 low2=-0.5*c[0].sup();
00979 }
00980
00981 c[2]=I(low,sup)*a[2];
00982 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
00983 }
00984
00985 else if ((c[0].inf()>=0) && (c[0].sup()>=0) && (tmp.inf()<=0) && (tmp.sup()<=0)){
00986 lowdiff=a[0].inf()-a[1].inf();
00987 supdiff=a[0].sup()-a[1].sup();
00988
00989 if (lowdiff!=0){
00990 sup=(sin(a[0].inf())-sin(a[1].inf()))/lowdiff;
00991 low2=(sup-cos(a[1].inf()))/lowdiff;
00992 }
00993 else {
00994 sup=cos(a[0].inf());
00995 low2=-0.5*c[0].inf();
00996 }
00997
00998 if (supdiff!=0){
00999 low=(sin(a[0].sup())-sin(a[1].sup()))/supdiff;
01000 sup2=(low-cos(a[1].sup()))/supdiff;
01001 }
01002 else {
01003 low=cos(a[0].sup());
01004 sup2=-0.5*c[0].sup();
01005 }
01006
01007 c[2]=I(low,sup)*a[2];
01008 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01009
01010
01011
01012 }
01013
01014 else if ((c[0].inf()<=0) && (c[0].sup()<=0) && (tmp.inf()<=0) && (tmp.sup()<=0)){
01015 lowdiff=a[0].inf()-a[1].inf();
01016 supdiff=a[0].sup()-a[1].sup();
01017
01018 if (lowdiff!=0){
01019 low=(sin(a[0].inf())-sin(a[1].inf()))/lowdiff;
01020 low2=(low-cos(a[1].inf()))/lowdiff;
01021 }
01022 else {
01023 low=cos(a[0].inf());
01024 low2=-0.5*c[0].inf();
01025 }
01026
01027 if (supdiff!=0){
01028 sup=(sin(a[0].sup())-sin(a[1].sup()))/supdiff;
01029 sup2=(sup-cos(a[1].sup()))/supdiff;
01030 }
01031 else {
01032 sup=cos(a[0].sup());
01033 sup2=-0.5*c[0].sup();
01034 }
01035
01036 c[2]=I(low,sup)*a[2];
01037 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01038
01039
01040
01041 }
01042
01043 else if ((c[0].inf()<=0) && (c[0].sup()<=0) && (tmp.inf()>=0) && (tmp.sup()>=0)){
01044 lowdiff=a[0].inf()-a[1].inf();
01045 supdiff=a[0].sup()-a[1].sup();
01046
01047 if (lowdiff!=0){
01048 low=(sin(a[0].inf())-sin(a[1].inf()))/lowdiff;
01049 sup2=(low-cos(a[1].inf()))/lowdiff;
01050 }
01051 else {
01052 low=cos(a[0].inf());
01053 sup2=-0.5*c[0].inf();
01054 }
01055
01056 if (supdiff!=0){
01057 sup=(sin(a[0].sup())-sin(a[1].sup()))/supdiff;
01058 low2=(sup-cos(a[1].sup()))/supdiff;
01059 }
01060 else {
01061 sup=cos(a[0].sup());
01062 low2=-0.5*c[0].sup();
01063 }
01064
01065 c[2]=I(low,sup)*a[2];
01066 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01067
01068
01069
01070 }
01071
01072 else {
01073 c[2]=cos(a[0])*a[2];
01074 c[5]=0.5*(-sin(a[0])*power(a[2],2))+cos(a[0])*a[5];
01075 }
01076
01077 if (c[5].empty()) {
01078 c[2]=cos(a[0])*a[2];
01079 c[5]=0.5*(-sin(a[0])*power(a[2],2))+cos(a[0])*a[5];
01080 }
01081
01082 c.minmaxval[0]=sin(a.minmaxval[0]);
01083 c.minmaxval[1]=sin(a.minmaxval[1]);
01084
01085 d=c;
01086 }
01087 return d;
01088 }
01089
01090 inline Islope cos(const Islope &a)
01091 {
01092 Islope d;
01093 double low;
01094 double sup;
01095 double low2;
01096 double sup2;
01097 double lowdiff;
01098 double supdiff;
01099
01100 if (a.order==1){
01101 Islope c;
01102 c[0]=cos(a[0]);
01103 c[0]=cos(a[0]);
01104 c[1]=cos(a[1]);
01105 if (width(a[0])>=U_PI){
01106 c[2]=-sin(a[0])*a[2];
01107 }
01108
01109 else if ((c[0].inf()<=0) && (c[0].sup()<=0)){
01110 lowdiff=a[0].inf()-a[1].inf();
01111 supdiff=a[0].sup()-a[1].sup();
01112
01113 if (lowdiff!=0){
01114 low=(cos(a[0].inf())-cos(a[1].inf()))/lowdiff;
01115 }
01116 else {
01117 low=-sin(a[0].inf());
01118 }
01119
01120 if (supdiff!=0){
01121 sup=(cos(a[0].sup())-cos(a[1].sup()))/supdiff;
01122 }
01123 else {
01124 sup=-sin(a[0].sup());
01125 }
01126
01127 c[2]=I(low,sup)*a[2];
01128 }
01129
01130 else if ((c[0].inf()>=0) && (c[0].sup()>=0)){
01131 lowdiff=a[0].inf()-a[1].inf();
01132 supdiff=a[0].sup()-a[1].sup();
01133
01134 if (lowdiff!=0){
01135 sup=(cos(a[0].inf())-cos(a[1].inf()))/lowdiff;
01136 }
01137 else {
01138 sup=-sin(a[0].inf());
01139 }
01140
01141 if (supdiff!=0){
01142 low=(cos(a[0].sup())-cos(a[1].sup()))/supdiff;
01143 }
01144 else {
01145 low=-sin(a[0].sup());
01146 }
01147 c[2]=I(low,sup)*a[2];
01148 }
01149
01150 else {
01151 c[2]=-sin(a[0])*a[2];
01152 }
01153
01154 d=c;
01155 }
01156
01157 if (a.order==2){
01158 Islope c(2);
01159 d.order=2;
01160 c[0]=cos(a[0]);
01161 c[0]=cos(a[0]);
01162 c[1]=cos(a[1]);
01163 c[3]=cos(a[3]);
01164 c[4]=-sin(a[1])*a[4];
01165 c[6]=a[6];
01166 I tmp=sin(a[0]);
01167 if (width(a[0])>=U_PI/2.){
01168 c[2]=cos(a[0])*a[2];
01169 c[5]=0.5*(-cos(a[0])*power(a[2],2))-sin(a[0])*a[5];
01170 }
01171
01172 else if ((c[0].inf()>=0) && (c[0].sup()>=0) && (tmp.inf()>=0) && (tmp.sup()>=0)){
01173 lowdiff=a[0].inf()-a[1].inf();
01174 supdiff=a[0].sup()-a[1].sup();
01175
01176 if (lowdiff!=0){
01177 sup=(cos(a[0].inf())-cos(a[1].inf()))/lowdiff;
01178 sup2=(sup+sin(a[1].inf()))/lowdiff;
01179 }
01180 else {
01181 sup=-sin(a[0].inf());
01182 sup2=-0.5*c[0].inf();
01183 }
01184
01185 if (supdiff!=0){
01186 low=(cos(a[0].sup())-cos(a[1].sup()))/supdiff;
01187 low2=(low+sin(a[1].sup()))/supdiff;
01188 }
01189 else {
01190 low=-sin(a[0].sup());
01191 low2=-0.5*c[0].sup();
01192 }
01193
01194 c[2]=I(low,sup)*a[2];
01195 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01196 }
01197
01198 else if ((c[0].inf()>=0) && (c[0].sup()>=0) && (tmp.inf()<=0) && (tmp.sup()<=0)){
01199 lowdiff=a[0].inf()-a[1].inf();
01200 supdiff=a[0].sup()-a[1].sup();
01201
01202 if (lowdiff!=0){
01203 sup=(cos(a[0].inf())-cos(a[1].inf()))/lowdiff;
01204 low2=(sup+sin(a[1].inf()))/lowdiff;
01205 }
01206 else {
01207 sup=-sin(a[0].inf());
01208 low2=-0.5*c[0].inf();
01209 }
01210
01211 if (supdiff!=0){
01212 low=(cos(a[0].sup())-cos(a[1].sup()))/supdiff;
01213 sup2=(low+sin(a[1].sup()))/supdiff;
01214 }
01215 else {
01216 low=-sin(a[0].sup());
01217 sup2=-0.5*c[0].sup();
01218 }
01219
01220 c[2]=I(low,sup)*a[2];
01221 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01222
01223
01224
01225 }
01226
01227 else if ((c[0].inf()<=0) && (c[0].sup()<=0) && (tmp.inf()<=0) && (tmp.sup()<=0)){
01228 lowdiff=a[0].inf()-a[1].inf();
01229 supdiff=a[0].sup()-a[1].sup();
01230
01231 if (lowdiff!=0){
01232 low=(cos(a[0].inf())-cos(a[1].inf()))/lowdiff;
01233 low2=(low+sin(a[1].inf()))/lowdiff;
01234 }
01235 else {
01236 low=-sin(a[0].inf());
01237 low2=-0.5*c[0].inf();
01238 }
01239
01240 if (supdiff!=0){
01241 sup=(cos(a[0].sup())-cos(a[1].sup()))/supdiff;
01242 sup2=(sup+sin(a[1].sup()))/supdiff;
01243 }
01244 else {
01245 sup=-sin(a[0].sup());
01246 sup2=-0.5*c[0].sup();
01247 }
01248
01249 c[2]=I(low,sup)*a[2];
01250 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01251
01252
01253
01254 }
01255
01256 else if ((c[0].inf()<=0) && (c[0].sup()<=0) && (tmp.inf()>=0) && (tmp.sup()>=0)){
01257 lowdiff=a[0].inf()-a[1].inf();
01258 supdiff=a[0].sup()-a[1].sup();
01259
01260 if (lowdiff!=0){
01261 low=(cos(a[0].inf())-cos(a[1].inf()))/lowdiff;
01262 sup2=(low+sin(a[1].inf()))/lowdiff;
01263 }
01264 else {
01265 low=-sin(a[0].inf());
01266 sup2=-0.5*c[0].inf();
01267 }
01268
01269 if (supdiff!=0){
01270 sup=(cos(a[0].sup())-cos(a[1].sup()))/supdiff;
01271 low2=(sup+sin(a[1].sup()))/supdiff;
01272 }
01273 else {
01274 sup=-sin(a[0].sup());
01275 low2=-0.5*c[0].sup();
01276 }
01277
01278 c[2]=I(low,sup)*a[2];
01279 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01280
01281
01282
01283 }
01284
01285 else {
01286 c[2]=-sin(a[0])*a[2];
01287 c[5]=0.5*(-cos(a[0])*power(a[2],2))-sin(a[0])*a[5];
01288 }
01289
01290 if (c[5].empty()) {
01291 c[2]=-sin(a[0])*a[2];
01292 c[5]=0.5*(-cos(a[0])*power(a[2],2))-sin(a[0])*a[5];
01293 }
01294
01295 c.minmaxval[0]=cos(a.minmaxval[0]);
01296 c.minmaxval[1]=cos(a.minmaxval[1]);
01297
01298 d=c;
01299 }
01300 return d;
01301 }
01302
01303 inline Islope sqrt(const Islope &a)
01304 {
01305 if (a[0].inf()<0){
01306 std::cerr<<"sqrt: interval contains negative numbers";
01307 abort();
01308 }
01309 Islope d;
01310
01311 if (a.order==1){
01312 Islope c;
01313 c[0]=sqrt(a[0]);
01314 c[1]=sqrt(a[1]);
01315 c[2]=a[2]/(c[0]+c[1]);
01316 d=c;
01317 }
01318
01319 if (a.order==2){
01320 Islope c(2);
01321 d.order=2;
01322 c[0]=sqrt(a[0]);
01323 c[1]=sqrt(a[1]);
01324 c[3]=sqrt(a[3]);
01325 c[6]=a[6];
01326
01327
01328
01329
01330
01331
01332
01333
01334 c[2]=a[2]/(c[0]+c[1]);
01335 c[4]=a[4]/(2.*c[1]);
01336 c[5]=a[5]/(c[0]+c[1])-a[4]*a[2]/(power(c[0]+c[1],2)*4.*c[1]);
01337
01338 c.minmaxval[0]=sqrt(a.minmaxval[0]);
01339 c.minmaxval[1]=sqrt(a.minmaxval[1]);
01340 d=c;
01341 }
01342 return d;
01343 }
01344
01345 inline Islope power(const Islope &a, int n)
01346 {
01347 if (n<2){
01348 std::cerr<<"power degree not supported: "<< n;
01349 abort();
01350 }
01351 Islope d;
01352 if (a.order==1){
01353 Islope c;
01354 c[0]=power(a[0], n);
01355 c[1]=power(a[1], n);
01356 double lowdiff=a[0].inf()-a[1].inf();
01357 double supdiff=a[0].sup()-a[1].sup();
01358 switch (n % 2) {
01359 case 0: if (n == 2) {
01360 c[2]=a[2] * (a[0] + a[1]);
01361 }
01362 else if ((lowdiff != 0) && (supdiff != 0)) {
01363 double low=(pow(a[0].inf(),n)-pow(a[1].inf(),n))/lowdiff;
01364 double sup=(pow(a[0].sup(),n)-pow(a[1].sup(),n))/supdiff;
01365 c[2]=I(low,sup)*a[2];
01366 }
01367 else if ((lowdiff == 0) && (supdiff != 0)) {
01368 double low=n*pow(a[0].inf(),n-1);
01369 double sup=(pow(a[0].sup(),n)-pow(a[1].sup(),n))/supdiff;
01370 c[2]=I(low,sup)*a[2];
01371 }
01372 else if ((lowdiff != 0) && (supdiff == 0)) {
01373 double low=(pow(a[0].inf(),n)-pow(a[1].inf(),n))/lowdiff;
01374 double sup=n*pow(a[0].sup(),n-1);
01375 c[2]=I(low,sup)*a[2];
01376 }
01377 else c[2]=n*power(a[0],n-1)*a[2];
01378 break;
01379 case 1: if ((a[0].inf() >= 0) && (lowdiff != 0) && (supdiff != 0)) {
01380 double low=(pow(a[0].inf(),n)-pow(a[1].inf(),n))/lowdiff;
01381 double sup=(pow(a[0].sup(),n)-pow(a[1].sup(),n))/supdiff;
01382 c[2]=I(low,sup)*a[2];
01383 }
01384 else if ((a[0].inf() >= 0) && (lowdiff == 0) && (supdiff != 0)) {
01385 double low=n*pow(a[0].inf(),n-1);
01386 double sup=(pow(a[0].sup(),n)-pow(a[1].sup(),n))/supdiff;
01387 c[2]=I(low,sup)*a[2];
01388 }
01389 else if ((a[0].inf() >= 0) && (lowdiff != 0) && (supdiff == 0)) {
01390 double low=(pow(a[0].inf(),n)-pow(a[1].inf(),n))/lowdiff;
01391 double sup=n*pow(a[0].sup(),n-1);
01392 c[2]=I(low,sup)*a[2];
01393 }
01394 else if ((a[0].sup() <= 0) && (lowdiff != 0) && (supdiff != 0)) {
01395 double sup=(pow(a[0].inf(),n)-pow(a[1].inf(),n))/lowdiff;
01396 double low=(pow(a[0].sup(),n)-pow(a[1].sup(),n))/supdiff;
01397 c[2]=I(low,sup)*a[2];
01398 }
01399 else if ((a[0].sup() <= 0) && (lowdiff == 0) && (supdiff != 0)) {
01400 double sup=n*pow(a[0].inf(),n-1);
01401 double low=(pow(a[0].sup(),n)-pow(a[1].sup(),n))/supdiff;
01402 c[2]=I(low,sup)*a[2];
01403 }
01404 else if ((a[0].sup() <= 0) && (lowdiff != 0) && (supdiff == 0)) {
01405 double sup=(pow(a[0].inf(),n)-pow(a[1].inf(),n))/lowdiff;
01406 double low=n*pow(a[0].sup(),n-1);
01407 c[2]=I(low,sup)*a[2];
01408 }
01409 else c[2]=n*power(a[0],n-1)*a[2];
01410 break;
01411 }
01412 d=c;
01413 }
01414 if (a.order==2){
01415 Islope c(2);
01416 d.order=2;
01417 c[0]=power(a[0], n);
01418 c[1]=power(a[1], n);
01419 c[3]=power(a[3], n);
01420 c[6]=a[6];
01421 double lowdiff=a[0].inf()-a[1].inf();
01422 double supdiff=a[0].sup()-a[1].sup();
01423 switch (n % 2) {
01424 case 0: if (n == 2) {
01425 c[2]=a[2] * (a[0] + a[1]);
01426 c[4]=2.*a[1]*a[4];
01427 c[5]=(a[0]+a[1])*a[5]+a[4]*a[2];
01428 }
01429 else if ((a[0].inf() >= 0) && (lowdiff != 0) && (supdiff != 0)) {
01430 double low=(pow(a[0].inf(),n)-pow(a[1].inf(),n))/lowdiff;
01431 double sup=(pow(a[0].sup(),n)-pow(a[1].sup(),n))/supdiff;
01432 c[2]=I(low,sup)*a[2];
01433 c[4]=n*power(a[1],n-1)*a[4];
01434 double low2=(low-n*pow(a[1].inf(),n-1))/lowdiff;
01435 double sup2=(sup-n*pow(a[1].sup(),n-1))/supdiff;
01436 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01437
01438 }
01439 else if ((a[0].inf() >= 0) && (lowdiff == 0) && (supdiff != 0)) {
01440 double low=n*pow(a[0].inf(),n-1);
01441 double sup=(pow(a[0].sup(),n)-pow(a[1].sup(),n))/supdiff;
01442 c[2]=I(low,sup)*a[2];
01443 c[4]=n*power(a[1],n-1)*a[4];
01444 double low2=n*(n-1)*pow(a[0].inf(),n-2);
01445 double sup2=(sup-n*pow(a[1].sup(),n-1))/supdiff;
01446 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01447
01448 }
01449 else if ((a[0].inf() >= 0) && (lowdiff != 0) && (supdiff == 0)) {
01450 double low=(pow(a[0].inf(),n)-pow(a[1].inf(),n))/lowdiff;
01451 double sup=n*pow(a[0].sup(),n-1);
01452 c[2]=I(low,sup)*a[2];
01453 c[4]=n*power(a[1],n-1)*a[4];
01454 double low2=(low-c[1].inf())/lowdiff;
01455 double sup2=n*(n-1)*pow(a[0].sup(),n-2);
01456 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01457 }
01458 else if ((a[0].sup() <= 0) && (lowdiff != 0) && (supdiff != 0)) {
01459 double low=(pow(a[0].inf(),n)-pow(a[1].inf(),n))/lowdiff;
01460 double sup=(pow(a[0].sup(),n)-pow(a[1].sup(),n))/supdiff;
01461 c[2]=I(low,sup)*a[2];
01462 c[4]=n*power(a[1],n-1)*a[4];
01463 double sup2=(sup-n*pow(a[1].inf(),n-1))/lowdiff;
01464 double low2=(low-n*pow(a[1].sup(),n-1))/supdiff;
01465 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01466 }
01467 else if ((a[0].sup() <= 0) && (lowdiff == 0) && (supdiff != 0)) {
01468 double low=n*pow(a[0].inf(),n-1);
01469 double sup=(pow(a[0].sup(),n)-pow(a[1].sup(),n))/supdiff;
01470 c[2]=I(low,sup)*a[2];
01471 c[4]=n*power(a[1],n-1)*a[4];
01472 double sup2=n*(n-1)*pow(a[0].inf(),n-2);
01473 double low2=(low-n*pow(a[1].sup(),n-1))/supdiff;
01474 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01475 }
01476 else if ((a[0].sup() <= 0) && (lowdiff != 0) && (supdiff == 0)) {
01477 double low=(pow(a[0].inf(),n)-pow(a[1].inf(),n))/lowdiff;
01478 double sup=n*pow(a[0].sup(),n-1);
01479 c[2]=I(low,sup)*a[2];
01480 c[4]=n*power(a[1],n-1)*a[4];
01481 double sup2=(sup-n*pow(a[1].inf(),n-1))/lowdiff;
01482 double low2=n*(n-1)*pow(a[0].sup(),n-2);
01483 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01484 }
01485 else {
01486 c[2]=n*power(a[0],n-1)*a[2];
01487 c[4]=n*power(a[1],n-1)*a[4];
01488 c[5]=0.5*(n*(n-1)*power(a[0],n-2)*power(a[2],2))+n*power(a[0],n-1)*a[5];
01489 }
01490
01491 if (c[5].empty()){
01492 c[2]=n*power(a[0],n-1)*a[2];
01493 c[4]=n*power(a[1],n-1)*a[4];
01494 c[5]=0.5*(n*(n-1)*power(a[0],n-2)*power(a[2],2))+n*power(a[0],n-1)*a[5];
01495
01496 }
01497 break;
01498 case 1: if ((a[0].inf() >= 0) && (lowdiff != 0) && (supdiff != 0)) {
01499 double low=(pow(a[0].inf(),n)-pow(a[1].inf(),n))/lowdiff;
01500 double sup=(pow(a[0].sup(),n)-pow(a[1].sup(),n))/supdiff;
01501 c[2]=I(low,sup)*a[2];
01502 c[4]=n*power(a[1],n-1)*a[4];
01503 double low2=(low-n*pow(a[1].inf(),n-1))/lowdiff;
01504 double sup2=(sup-n*pow(a[1].sup(),n-1))/supdiff;
01505 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01506 }
01507 else if ((a[0].inf() >= 0) && (lowdiff == 0) && (supdiff != 0)) {
01508 double low=n*pow(a[0].inf(),n-1);
01509 double sup=(pow(a[0].sup(),n)-pow(a[1].sup(),n))/supdiff;
01510 c[2]=I(low,sup)*a[2];
01511 c[4]=n*power(a[1],n-1)*a[4];
01512 double low2=n*(n-1)*pow(a[0].inf(),n-2);
01513 double sup2=(sup-n*pow(a[1].sup(),n-1))/supdiff;
01514 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01515 }
01516 else if ((a[0].inf() >= 0) && (lowdiff != 0) && (supdiff == 0)) {
01517 double low=(pow(a[0].inf(),n)-pow(a[1].inf(),n))/lowdiff;
01518 double sup=n*pow(a[0].sup(),n-1);
01519 c[2]=I(low,sup)*a[2];
01520 c[4]=n*power(a[1],n-1)*a[4];
01521 double low2=(low-c[1].inf())/lowdiff;
01522 double sup2=n*(n-1)*pow(a[0].sup(),n-2);
01523 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01524 }
01525 else if ((a[0].sup() <= 0) && (lowdiff != 0) && (supdiff != 0)) {
01526 double sup=(pow(a[0].inf(),n)-pow(a[1].inf(),n))/lowdiff;
01527 double low=(pow(a[0].sup(),n)-pow(a[1].sup(),n))/supdiff;
01528 c[2]=I(low,sup)*a[2];
01529 c[4]=n*power(a[1],n-1)*a[4];
01530 double low2=(sup-n*pow(a[1].inf(),n-1))/lowdiff;
01531 double sup2=(low-n*pow(a[1].sup(),n-1))/supdiff;
01532 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01533 }
01534 else if ((a[0].sup() <= 0) && (lowdiff == 0) && (supdiff != 0)) {
01535 double sup=n*pow(a[0].inf(),n-1);
01536 double low=(pow(a[0].sup(),n)-pow(a[1].sup(),n))/supdiff;
01537 c[2]=I(low,sup)*a[2];
01538 c[4]=n*power(a[1],n-1)*a[4];
01539 double low2=n*(n-1)*pow(a[0].inf(),n-2);
01540 double sup2=(low-n*pow(a[1].sup(),n-1))/supdiff;
01541 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01542 }
01543 else if ((a[0].sup() <= 0) && (lowdiff != 0) && (supdiff == 0)) {
01544 double sup=(pow(a[0].inf(),n)-pow(a[1].inf(),n))/lowdiff;
01545 double low=n*pow(a[0].sup(),n-1);
01546 c[2]=I(low,sup)*a[2];
01547 c[4]=n*power(a[1],n-1)*a[4];
01548 double low2=(sup-n*pow(a[1].inf(),n-1))/lowdiff;
01549 double sup2=n*(n-1)*pow(a[0].sup(),n-2);
01550 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01551 }
01552 else {
01553 c[2]=n*power(a[0],n-1)*a[2];
01554 c[4]=n*power(a[1],n-1)*a[4];
01555 c[5]=0.5*(n*(n-1)*power(a[0],n-2)*power(a[2],2))+n*power(a[0],n-1)*a[5];
01556 }
01557
01558 if (c[5].empty()) {
01559 c[2]=n*power(a[0],n-1)*a[2];
01560 c[4]=n*power(a[1],n-1)*a[4];
01561 c[5]=0.5*(n*(n-1)*power(a[0],n-2)*power(a[2],2))+n*power(a[0],n-1)*a[5];
01562 }
01563 break;
01564 }
01565
01566 c.minmaxval[0]=pow(a.minmaxval[0],n);
01567 c.minmaxval[1]=pow(a.minmaxval[1],n);
01568 d=c;
01569 }
01570 return d;
01571 }
01572
01573 inline Islope log(const Islope &a)
01574 {
01575 if (a[0].inf()<0){
01576 std::cerr<<"log: interval contains negative numbers";
01577 abort();
01578 }
01579 Islope d;
01580 if (a.order==1){
01581 Islope c;
01582 c[0]=log(a[0]);
01583 c[1]=log(a[1]);
01584 double lowdiff=a[0].inf()-a[1].inf();
01585 double supdiff=a[0].sup()-a[1].sup();
01586 if ((lowdiff==0)&&(supdiff==0)){
01587 c[2]=a[2]/a[0];
01588 }
01589 if ((lowdiff!=0)&&(supdiff!=0)) {
01590 double sup=(log(a[0].inf())-log(a[1].inf()))/lowdiff;
01591 double low=(log(a[0].sup())-log(a[1].sup()))/supdiff;
01592 c[2]=I(low,sup)*a[2];
01593 }
01594 if ((lowdiff!=0)&&(supdiff==0)) {
01595 double sup=(log(a[0].inf())-log(a[1].inf()))/lowdiff;
01596 double low=1./a[0].sup();
01597 c[2]=I(low,sup)*a[2];
01598 }
01599 if ((lowdiff==0)&&(supdiff!=0)) {
01600 double sup=1./a[0].inf();
01601 double low=(log(a[0].sup())-log(a[1].sup()))/supdiff;
01602 c[2]=I(low,sup)*a[2];
01603 }
01604 d=c;
01605 }
01606 if (a.order==2){
01607 Islope c(2);
01608 d.order=2;
01609 c[0]=log(a[0]);
01610 c[1]=log(a[1]);
01611 c[3]=log(a[3]);
01612 c[6]=a[6];
01613 double lowdiff=a[0].inf()-a[1].inf();
01614 double supdiff=a[0].sup()-a[1].sup();
01615 if ((lowdiff==0)&&(supdiff==0)){
01616 c[2]=a[2]/a[0];
01617 c[4]=a[4]/a[1];
01618 c[5]=a[5]/a[0]-0.5*power(a[2],2)/power(a[0],2);
01619 }
01620 if ((lowdiff!=0)&&(supdiff!=0)){
01621 double sup=(log(a[0].inf())-log(a[1].inf()))/lowdiff;
01622 double low=(log(a[0].sup())-log(a[1].sup()))/supdiff;
01623 c[2]=I(low,sup)*a[2];
01624 c[4]=a[4]/a[1];
01625 double sup2=(low-1./a[1].sup())/supdiff;
01626 double low2=(sup-1./a[1].inf())/lowdiff;
01627 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01628 }
01629 if ((lowdiff!=0)&&(supdiff==0)){
01630 double sup=(log(a[0].inf())-log(a[1].inf()))/lowdiff;
01631 double low=1./a[0].sup();
01632 c[2]=I(low,sup)*a[2];
01633 c[4]=a[4]/a[1];
01634 double sup2=-0.5/pow(a[0].sup(),2);
01635 double low2=(sup-1./a[1].inf())/lowdiff;
01636 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01637 }
01638 if ((lowdiff==0)&&(supdiff!=0)){
01639 double sup=1./a[0].inf();
01640 double low=(log(a[0].sup())-log(a[1].sup()))/supdiff;
01641 c[2]=I(low,sup)*a[2];
01642 c[4]=a[4]/a[1];
01643 double sup2=(low-1./a[1].sup())/supdiff;
01644 double low2=-0.5/pow(a[0].inf(),2);
01645 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01646 }
01647 if (c[5].empty()){
01648 c[2]=a[2]/a[0];
01649 c[5]=a[5]/a[0]-0.5*power(a[2],2)/power(a[0],2);
01650 }
01651 c.minmaxval[0]=log(a.minmaxval[0]);
01652 c.minmaxval[1]=log(a.minmaxval[1]);
01653 d=c;
01654 }
01655 return d;
01656 }
01657
01658 inline Islope atan(const Islope &a)
01659 {
01660 Islope d;
01661 if (a.order==1){
01662 Islope c;
01663 c[0]=atan(a[0]);
01664 c[1]=atan(a[1]);
01665 double lowdiff=a[0].inf()-a[1].inf();
01666 double supdiff=a[0].sup()-a[1].sup();
01667
01668 if ((a[0].inf() >= 0) && (lowdiff != 0) && (supdiff != 0)) {
01669 double sup=(atan(a[0].inf())-atan(a[1].inf()))/lowdiff;
01670 double low=(atan(a[0].sup())-atan(a[1].sup()))/supdiff;
01671 c[2]=I(low,sup)*a[2];
01672 }
01673 else if ((a[0].sup() <= 0) && (lowdiff != 0) && (supdiff != 0)) {
01674 double low=(atan(a[0].inf())-atan(a[1].inf()))/lowdiff;
01675 double sup=(atan(a[0].sup())-atan(a[1].sup()))/supdiff;
01676 c[2]=I(low,sup)*a[2];
01677 }
01678 else c[2]=a[2]/(1.+power(a[0],2));
01679 d=c;
01680 }
01681 if (a.order==2){
01682 Islope c(2);
01683 d.order=2;
01684 c[0]=atan(a[0]);
01685 c[1]=atan(a[1]);
01686 c[3]=atan(a[3]);
01687 c[6]=a[6];
01688 double lowdiff=a[0].inf()-a[1].inf();
01689 double supdiff=a[0].sup()-a[1].sup();
01690
01691 if ((a[0].inf() >= sqrt(3.)/3) && (lowdiff != 0) && (supdiff != 0)) {
01692 double sup=(atan(a[0].inf())-atan(a[1].inf()))/lowdiff;
01693 double low=(atan(a[0].sup())-atan(a[1].sup()))/supdiff;
01694 c[2]=I(low,sup)*a[2];
01695 c[4]=a[4]/(1.+power(a[1],2));
01696 double sup2=(low-1./(1.+power(a[1],2).sup()))/supdiff;
01697 double low2=(sup-1./(1.+power(a[1],2).inf()))/lowdiff;
01698 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01699 std::cout<<"daaaaaaaaaa"<<c[5];
01700 }
01701 else if ((a[0].inf() >= 0) && (a[0].sup() <= sqrt(3.)/3) && (lowdiff != 0) && (supdiff != 0)) {
01702 double sup=(atan(a[0].inf())-atan(a[1].inf()))/lowdiff;
01703 double low=(atan(a[0].sup())-atan(a[1].sup()))/supdiff;
01704 c[2]=I(low,sup)*a[2];
01705 c[4]=a[4]/(1.+power(a[1],2));
01706 double low2=(low-1./(1.+power(a[1],2).sup()))/supdiff;
01707 double sup2=(sup-1./(1.+power(a[1],2).inf()))/lowdiff;
01708 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01709 }
01710 else if ((a[0].inf() >= -sqrt(3.)/3) && (a[0].sup() <= 0) && (lowdiff != 0) && (supdiff != 0)) {
01711 double low=(atan(a[0].inf())-atan(a[1].inf()))/lowdiff;
01712 double sup=(atan(a[0].sup())-atan(a[1].sup()))/supdiff;
01713 c[2]=I(low,sup)*a[2];
01714 c[4]=a[4]/(1.+power(a[1],2));
01715 double low2=(sup-1./(1.+power(a[1],2).sup()))/supdiff;
01716 double sup2=(low-1./(1.+power(a[1],2).inf()))/lowdiff;
01717 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01718 }
01719 else if ((a[0].sup() <= -sqrt(3.)/3) && (lowdiff != 0) && (supdiff != 0)) {
01720 double low=(atan(a[0].inf())-atan(a[1].inf()))/lowdiff;
01721 double sup=(atan(a[0].sup())-atan(a[1].sup()))/supdiff;
01722 c[2]=I(low,sup)*a[2];
01723 c[4]=a[4]/(1.+power(a[1],2));
01724 double sup2=(sup-1./(1.+power(a[1],2).sup()))/supdiff;
01725 double low2=(low-1./(1.+power(a[1],2).inf()))/lowdiff;
01726 c[5]=I(low,sup)*a[5]+I(low2,sup2)*a[4]*a[2];
01727 }
01728 else {
01729 c[2]=a[2]/(1.+power(a[0],2));
01730 c[4]=a[4]/(1.+power(a[1],2));
01731 c[5]=-a[0]*power(a[2],2)/(power(1.+power(a[0],2),2))+a[5]/(1.+power(a[0],2));
01732 std::cout<<"hier";
01733 }
01734
01735 if (c[5].empty()){
01736 c[2]=a[2]/(1.+power(a[0],2));
01737 c[5]=-a[0]*power(a[2],2)/(power(1.+power(a[0],2),2))+a[5]/(1.+power(a[0],2));
01738 }
01739 c.minmaxval[0]=atan(a.minmaxval[0]);
01740 c.minmaxval[1]=atan(a.minmaxval[1]);
01741 d=c;
01742 }
01743
01744 return d;
01745 }
01746
01747 inline Islope atan2(const Islope &a, const Islope &b)
01748 {
01749 Islope c;
01750 c=b/a;
01751 c=atan(c);
01752 return c;
01753 }
01754
01755
01756 inline Islope::~Islope()
01757 {
01758 if (data) delete data;
01759 }
01760
01761 inline std::ostream &operator << (std::ostream &s, const Islope &a)
01762 {
01763 if (a.order==1){
01764 s<<"< Range=";
01765 s<<a[0];
01766 s<<", Fixed Point=";
01767 s<<a[1];
01768 s<<", Slope=";
01769 s<<a[2];
01770 s<<" >\n";
01771 }
01772 if (a.order==2){
01773 s.precision(6);
01774 s<<std::showpoint;
01775 double slopemin_fmin=a[5].inf()*pow((a[6].inf()-a[6].sup()),2)/4.+(a[6].inf()-a[6].sup())*a[4].inf()/2.+a[1].inf();
01776 double slopemax_fmin=a[5].sup()*pow((a[6].inf()-a[6].sup()),2)/4.+(a[6].inf()-a[6].sup())*a[4].sup()/2.+a[1].sup();
01777 double slopemin_fmax=a[5].inf()*pow((a[6].inf()-a[6].sup()),2)/4.-(a[6].inf()-a[6].sup())*a[4].inf()/2.+a[1].inf();
01778 double slopemax_fmax=a[5].sup()*pow((a[6].inf()-a[6].sup()),2)/4.-(a[6].inf()-a[6].sup())*a[4].sup()/2.+a[1].sup();
01779 double slopemin1_fmin=-a[2].inf()*(a[6].sup()-a[6].inf())/2.+a[1].inf();
01780 double slopemax1_fmin=-a[2].sup()*(a[6].sup()-a[6].inf())/2.+a[1].sup();
01781 double slopemin1_fmax=a[2].inf()*(a[6].sup()-a[6].inf())/2.+a[1].inf();
01782 double slopemax1_fmax=a[2].sup()*(a[6].sup()-a[6].inf())/2.+a[1].sup();
01783 s<<"Range_x=";
01784 s<<a[0];
01785 s<<", Fixed Point_z=";
01786 s<<a[1];
01787 s<<"\n";
01788 s<<"Slope_x=";
01789 s<<a[2];
01790 s<<", Fixed Point_y=";
01791 s<<a[3];
01792 s<<"\n";
01793 s<<"Slope_2=";
01794 s<<a[5];
01795 s<<", Diff_z= ";
01796 s<<a[4];
01797 s<<"\n";
01798 s<<"+---------------------------------------------------------+\n";
01799 s<<"| slope_min real slope_max |\n";
01800 s<<"| f(min)= f(min)= f(min)= |\n";
01801 s<<"| order 1 ";
01802 s.width(12);
01803 s<<slopemin1_fmin;
01804 s.width(12);
01805 s<<a.minmaxval[0];
01806 s.width(12);
01807 s<<slopemax1_fmin;
01808 s<<" |\n";
01809 s<<"| order 2 ";
01810 s.width(12);
01811 s<<slopemin_fmin;
01812 s.width(12);
01813 s<<a.minmaxval[0];
01814 s.width(12);
01815 s<<slopemax_fmin;
01816 s<<" |\n";
01817 s<<"| f(max)= f(max)= f(max)= |\n";
01818 s<<"| order 1 ";
01819 s.width(12);
01820 s<<slopemin1_fmax;
01821 s.width(12);
01822 s<<a.minmaxval[1];
01823 s.width(12);
01824 s<<slopemax1_fmax;
01825 s<<" |\n";
01826 s<<"| order 2 ";
01827 s.width(12);
01828 s<<slopemin_fmax;
01829 s.width(12);
01830 s<<a.minmaxval[1];
01831 s.width(12);
01832 s<<slopemax_fmax;
01833 s<<" |\n";
01834 s<<"+---------------------------------------------------------+\n";
01835 if (((slopemin_fmin-a.minmaxval[0]<0) && (slopemax_fmin-a.minmaxval[0]<0)) || ((slopemin_fmin-a.minmaxval[0]>0) && (slopemax_fmin-a.minmaxval[0]>0))){
01836 s<<" !!slopefehler min!! "<<slopemin_fmin-a.minmaxval[0]<<" "<<slopemax_fmin-a.minmaxval[0]<<"\n";
01837 }
01838 if (((slopemin_fmax-a.minmaxval[1]<0) && (slopemax_fmax-a.minmaxval[1]<0)) || ((slopemin_fmax-a.minmaxval[1]>0) && (slopemax_fmax-a.minmaxval[1]>0))){
01839 s<<" !!slopefehler max!! "<<slopemin_fmax-a.minmaxval[1]<<" "<<slopemax_fmax-a.minmaxval[1]<<"\n";
01840 }
01841 s<<"\n";
01842 }
01843 return s;
01844 }
01845
01846 #endif