program bise1; (* 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 clrscr; gotoxy (10,3); write ('---------------------------------------------------'); gotoxy (10,4); write ('Questo programma riceve in input gli estremi a, b' ); gotoxy (10,5); write ('di un intervallo tali che una funzione f(x) assuma' ); gotoxy (10,6); write ('in essi valori di segno opposto. Viene calcolata, '); gotoxy (10,7); write ('con approssimazione arbitraria, una radice del- ' ); gotoxy (10,8); write ('l''equazione f(x)=0 interna all''intervallo. '); gotoxy (10,9); write ('La funzione f(x) definita nel programma. '); gotoxy (10,10); write ('---------------------------------------------------'); repeat gotoxy (25,13); write ('Estremo sinistro: '); read (A); gotoxy (25,14); write ('Estremo destro: ');read(B); until f(A)*f(B) < 0; {si accettano solo valori discordi di f(x)} gotoxy (25,15); write ('Errore = ');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 legge_dati; clrscr; writeln('A= ',A:5:6,' B= ', B :12:6); readln; calcola (A,B); readln; end.