37 lines
990 B
Plaintext
37 lines
990 B
Plaintext
|
function [resultat] = memeSigne(a, b)
|
||
|
if ((a <= 0 && b <= 0) || (a >= 0 && b >= 0))
|
||
|
resultat = %T; // Utilisez %T pour représenter "true" en Scilab
|
||
|
else
|
||
|
resultat = %F; // Utilisez %F pour représenter "false" en Scilab
|
||
|
end
|
||
|
endfunction
|
||
|
|
||
|
function [x] = dichotomie(f, xa, xb, eps)
|
||
|
fraction = 2;
|
||
|
difference = xb - xa;
|
||
|
x = xa + difference / fraction;
|
||
|
y = f[1]*x^2 + f[2]*x + f[3];
|
||
|
ya = f[1]*xa^2 + f[2]*xa + f[3];
|
||
|
yb = f[1]*xb^2 + f[2]*xb + f[3];
|
||
|
|
||
|
while (y <= -eps || y >= eps)
|
||
|
fraction = fraction * 2;
|
||
|
|
||
|
if (memeSigne(ya, y))
|
||
|
if (memeSigne(yb, y))
|
||
|
endfunction
|
||
|
xa = x;
|
||
|
x = x + difference / fraction;
|
||
|
else
|
||
|
xb = x;
|
||
|
x = x - difference / fraction;
|
||
|
end
|
||
|
|
||
|
y = f[1]*x^2 + f[2]*x + f[3];
|
||
|
ya = f[1]*xa^2 + f[2]*xa + f[3];
|
||
|
end
|
||
|
|
||
|
// Assigner la valeur de x en sortie de la fonction
|
||
|
x_out = x;
|
||
|
endfunction
|