Function Bisect

  • Uploaded by: Carlos Duarte
  • 0
  • 0
  • February 2021
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Function Bisect as PDF for free.

More details

  • Words: 437
  • Pages: 6
Loading documents preview...
FUNCTION Bisect(xl, xu, es, imax, xr, iter, ea) iter = 0 fl = f(xl) DO xrold = xr xr = (xl + xu) / 2 fr = f(xr) iter = iter + 1 lF xr ≠ 0 THEN ea = ABS((xr – xrold) / xr) * 100 END IF test = fl * fr IF test < 0 THEN xu = xr ELSE IF test > 0 THEN xl = xr fl = fr ELSE ea = 0 END IF IF ea < es OR iter ≥ imax EXIT END DO Bisect = xr END Bisect

FUNCTION ModFalsePos(xl, xu, es, imax, xr, iter, ea) iter = 0 fl = f(xl) fu = f(xu) DO xrold = xr xr = xu – fu * (xl – xu) / (fl – fu) fr = f(xr) iter = iter + 1 IF xr <> 0 THEN

ea = Abs((xr – xrold) / xr) * 100 END IF test = fl * fr IF test < 0 THEN xu = xr fu = f(xu) iu = 0 il = il +1 If il ≥ 2 THEN fl = fl / 2 ELSE IF test > 0 THEN xl = xr fl = f (xl) il = 0 iu = iu + 1 IF iu ≥ 2 THEN fu = fu / 2 ELSE ea = 0 END IF IF ea < es 0R iter ≥ imax THEN EXIT END DO ModFalsePos = xr END ModFalsePos

#include <stdio.h> #include #include <math.h>

void Lee_Datos(void); double Funcion(double X);

double a, b, Error; int Max_Iter;

int main(void) { double Error_Aprox, Prod; double Xr, Xn; int Ciclos = 0;

Lee_Datos(); if ( Funcion(a)*Funcion(b) > 0 ) printf("\n No existe Raiz en el intervalo ????"); else { Xr = ( a+b )/2; printf("\n-------------------------------------------"); Error_Aprox = 1;

printf("\n Ciclo a

b

Xn

Error");

printf("\n-------------------------------------------"); printf("\n%3d%10.4f%10.4f%10.4f",Ciclos,a,b,Xr);

while ( Ciclos <= Max_Iter && Error < Error_Aprox) { Prod = Funcion(a)*Funcion(Xr); if (Prod == 0) printf(" La raiz es %lf",Xr); else if (Prod < 0) b = Xr; else a = Xr; Xn = ( a+b )/2; Ciclos += 1; Error_Aprox = fabs((Xn-Xr)/Xn);

printf("\n%3d%10.4f%10.4f%10.4f%10.4f",Ciclos,a,b,Xn,Error_Aprox); Xr = Xn; } if ( Ciclos< Max_Iter) { printf("\n-------------------------------------------"); printf("\n\n La Raiz de la Ecuacion es => %lf",Xn);

printf("\n Se encontro en %d Iteraciones",Ciclos); } else printf("\n No se encontro raiz en %d Iteraciones",Ciclos);

} getch(); return 0; }

void Lee_Datos(void)

{ clrscr(); printf("\nDar el valor de Xi ........... "); scanf("%lf",&a); printf("Dar el valor de Xf ........... "); scanf("%lf",&b); printf("Cual es el Error Permitido ... "); scanf("%lf",&Error); printf("Cual es el Maximo de Ciclos .."); scanf("%d",&Max_Iter); }

double Funcion(double X) { return (pow((1+X),10)-1)/(X*pow((1+X),10)) - 5; }

Related Documents


More Documents from "Sonofspeed"