Commit 85454a7e authored by Grand Francois's avatar Grand Francois
Browse files

ajout de la fonction CalcX() pour simplifier les appels à Calc()

Dichotomie() : contournement de certaines valeurs initiales à NaN
Showing with 33 additions and 21 deletions
+33 -21
......@@ -15,6 +15,7 @@ export class Dichotomie extends Debug {
*/
constructor(private nub: Nub, private sVarCalc: string, dbg: boolean = false) {
super(dbg);
this.debug(nub);
}
/** Valeur inconnue à rechercher */
......@@ -45,7 +46,14 @@ export class Dichotomie extends Debug {
/**
* @note
*/
return this.nub.Equation(this.nub.sVarsEq[0]);
let r = this.nub.Equation(this.nub.sVarsEq[0]);
this.debug('dicho : Calcul(vX=' + this.vX + ')=' + r.vCalc);
return r;
}
private CalculX(x: number) {
this.vX = x
return this.Calcul();
}
/**
......@@ -58,12 +66,10 @@ export class Dichotomie extends Debug {
let res: Result;
let XminInit: number = 1E-8;
this.vX = XminInit;
let v1: number = this.Calcul().vCalc;
// let v1: number = this.CalculX(XminInit).vCalc;
let XmaxInit: number = Math.max(1, rInit) * 100;
this.vX = XmaxInit;
let v2: number = this.Calcul().vCalc;
// let v2: number = this.CalculX(XmaxInit).vCalc;
let DX = (XmaxInit - XminInit) / this.IDEFINT;
let nIterMax = Math.floor(Math.max(XmaxInit - rInit, rInit - XminInit) / DX + 1);
......@@ -72,20 +78,24 @@ export class Dichotomie extends Debug {
let X1 = rInit;
let X2 = rInit;
this.debug("rInit: " + rInit);
this.vX = rInit;
let v = this.Calcul().vCalc;
let v = this.CalculX(rInit).vCalc;
if (isNaN(v)) {
rInit += 1e-8;
v = this.CalculX(rInit).vCalc;
}
v1 = v;
v2 = v;
let v1 = v;
let v2 = v;
//** @todo : Chercher en dehors de l'intervalle en le décalant à droite ou à gauche en fonction de la valeur */
let nIter: number;
for (nIter = 1; nIter < nIterMax; nIter++) {
//Ouverture de l'intervalle des deux côtés : à droite puis à gauche
Xmax = Xmax + DX;
if (this.XOR(Xmax > XmaxInit, DX <= 0)) Xmax = XmaxInit;
this.vX = Xmax;
v = this.Calcul().vCalc;
if (this.XOR(Xmax > XmaxInit, DX <= 0))
Xmax = XmaxInit;
v = this.CalculX(Xmax).vCalc;
if (this.XOR(v1 < v2, v <= v2)) {
v2 = v;
X2 = Xmax;
......@@ -94,13 +104,13 @@ export class Dichotomie extends Debug {
v1 = v;
X1 = Xmax;
}
Xmin = Xmin - DX;
if (this.XOR(Xmin < XminInit, DX <= 0)) {
Xmin = XminInit;
}
this.vX = Xmin;
v = this.Calcul().vCalc;
v = this.CalculX(Xmin).vCalc;
if (this.XOR(v1 < v2, v <= v2)) {
v2 = v;
X2 = Xmin;
......@@ -109,7 +119,9 @@ export class Dichotomie extends Debug {
v1 = v;
X1 = Xmin;
}
if (this.XOR(rTarget > v1, rTarget >= v2)) { break; }
if (this.XOR(rTarget > v1, rTarget >= v2))
break;
}
this.debug("intervalle initial " + X1 + ", " + X2);
......@@ -119,13 +131,12 @@ export class Dichotomie extends Debug {
if (v2 < rTarget && v1 < rTarget) {
// Cote de l'eau trop basse pour passer le débit il faut ouvrir un autre ouvrage
this.vX = XmaxInit;
res = this.CalculX(XmaxInit);
}
else {
// Cote de l'eau trop grande il faut fermer l'ouvrage
this.vX = XminInit;
res = this.CalculX(XminInit);
}
res = this.Calcul();
res.extraVar["flag"] = -1; // la valeur cible n'est pas dans l'intervalle de recherche
return res;
}
......@@ -134,8 +145,9 @@ export class Dichotomie extends Debug {
this.debug("start dicho");
let X = rInit;
for (nIter = 1; nIter <= this.IDICMAX; nIter++) {
this.vX = X;
v = this.Calcul().vCalc;
// this.vX = X;
// v = this.Calcul().vCalc;
v = this.CalculX(X).vCalc;
if (rTarget != 0 && Math.abs(X1 - X2) <= rTol) { break; }
if (this.XOR(rTarget < v, v1 <= v2)) {
// rTarget < IQ et v(X1) > v(X2) ou pareil en inversant les inégalités
......@@ -149,7 +161,7 @@ export class Dichotomie extends Debug {
this.debug((X));
}
if (nIter == this.IDICMAX) {
res = this.Calcul();
res = this.Calcul(); // ????
res.extraVar["flag"] = -1; // la valeur cible n'est pas dans l'intervalle de recherche
return res;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment