ricerca soluzione con bisezione

esci algebraturbo.htm

 

program bise2b;
(* calcolo radici equazione con metodo bisezione *)
uses crt;
var A,B,MEDIO,AMPIEZZA,ERRORE,X,Y: real;

function f(X: real): real;
begin
f := X*X*X*X-7*X*X*X+2*X*X-100*X+610
end;



procedure legge_dati;

begin
repeat
writeln('funzione esempio=x^4-7x^3+2x^2-100x+610');
writeln('prova con valori indicati');
gotoxy (25,13); write ('Estremo sinistro 4 : '); read (A);
gotoxy (25,14); write ('Estremo destro 5 : ');read(B);
until f(A)*f(B) < 0; {si accettano solo valori discordi di f(x)}
gotoxy (25,15); write ('Errore 0.001 = ');read(ERRORE);
end;


procedure calcola (ESTREMO_S, ESTREMO_D: real);

begin

MEDIO := (ESTREMO_S+ESTREMO_D)/2;


if f(ESTREMO_S)*f(MEDIO) <= 0 then

ESTREMO_D := MEDIO
else
ESTREMO_S := MEDIO;


AMPIEZZA := ESTREMO_D - ESTREMO_S;

write('Estremo sin.: ', ESTREMO_S :5:8);
writeln(' Estremo des.:',ESTREMO_D :12:8);


if AMPIEZZA < ERRORE then
begin
writeln;
write ('Radice approssimata: ',MEDIO :0:8);
writeln (' Errore: ',ERRORE :0:9)
end
else
calcola (ESTREMO_S,ESTREMO_D);

end;

begin
clrscr;
legge_dati;
clrscr;
writeln('A= ',A:5:6,' B= ', B :12:6);
readln;
calcola (A,B);
writeln('premi enter');
readln;
end.