La Web del Programador: Comunidad de Programadores
 
    Pregunta:  65309 - ¿COMO HACER EL METODO DE BISECCION EN TURBO PASCAL?
Autor:  Joel Jarquin
Necesito urgentemente que alguien me de un ejemplo de como realizar un programa cualquiera con una funcion cualquiera resuelta con el Metodo de Biseccion en Turbo Pascal.
Muchas Gracias.

  Respuesta:  ramon
program biseccion;

uses
crt;
var
p, a, b, c, n : real;
cc, ca, cb, resultado, resul : real;
error, cont, l : integer;
sal : boolean;

function calculo(a : real) : real;
begin
calculo := cos(a) / a;
end;

function dato(x, y : integer) : integer;
var
tec : char;
pos : integer;
tex : string[5];
valo : integer;
begin
dato := 0;
fillchar(tex,6,' ');
tex[0] := chr(5);
pos := 1;
gotoxy(x,y);
repeat
tec := readkey;
if tec in[#48..#57] then
begin
tex[pos] := tec;
tex[0] := chr(pos);
gotoxy(x + pos,y);write(tex[pos]);
pos := pos + 1;
if pos > 5 then
pos := 5;
end;
if tec = #8 then
begin
pos := pos - 1;
if pos < 1 then
pos := 1;
tex[pos] := ' ';
tex[0] := chr(pos);
gotoxy(x + pos,y);write(tex[pos]);
end;
until (tec = #13) or (tec = #27);
if tec = #27 then
sal := true;
if tec = #13 then
begin
val(tex,valo,error);
dato := valo;
end;
end;

procedure entrada_datos;
begin
gotoxy(10,1);write('<<< Programa De biseccion >>>');
gotoxy(10,3);write('*** Entre los Datos ***');
gotoxy(10,4);write('Valor de A = ',' ','Primer Valor');
gotoxy(10,5);write('Valor de B = ',' ','Segundo Valor');
gotoxy(10,6);write('Valor de p = ',' ','Veces de Intentos');
a := dato(22,4);
if sal = false then
b := dato(22,5);
if sal = false then
p := dato(22,6);
end;

procedure calculamos;
begin
clrscr;
entrada_datos;
c := (a + b) / 2;
cc := calculo(c);
cont := 0;
repeat
n := b - c;
if (abs(n) < p) or (cc = 0.0) then
resultado := c
else
begin
cc := calculo(c);
cb := calculo(b);
resul := cb * cc;
if (resul < 0.0) then
a := c
else
b := c
end;
cont := cont + 1;
gotoxy(10,8);write(' Intentos : ',cont,' Salio : ',c);
c := (a + b) / 2;
until (abs(n) < p) or (cc = 0.0);
gotoxy(10,10);write(' El Resultado Es : ',resultado : 8:8);
end;

begin
clrscr;
calculamos;
readln;
end.