-
Notifications
You must be signed in to change notification settings - Fork 0
/
biseccion
83 lines (74 loc) · 1.72 KB
/
biseccion
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* SEGUNDO DEPARTAMENTAL MÉTODOS NUMÉRICOS
MÉTODO DE BISECCIÓN */
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <math.h>
#include "windows.h"
float function(float x)
{
return (3*pow(x,2)-18*(x)+15)/5;
}
int main( )
{
system("color 3f");
gotoxy(27,9);
printf("INSTITUTO POLIT%cCNICO NACIONAL",144);
gotoxy(16,11);
printf("E");
gotoxy(26,13);
printf("O");
gotoxy(33,15);
printf("M%cTODOS NUM%cRICOS",144,144);
gotoxy(29,17);
printf("S",181,224);
gotoxy(6,24);
printf("PRESIONE CUALQUIER TECLA PARA CONTINUAR");
getch();
system("cls");
system("color 5f");
printf ("METODO DE BISECCION\n\n");
float x1,x2,a,b,c,Li,Ls,Ea,pi,error,raiz;
int n;
printf("VALOR DE A EN ECUACION GENERAL: ");
scanf ("%f",&a);
printf("\nVALOR DE B EN ECUACION GENERAL: ");
scanf ("%f",&b);
printf("\nVALOR DE C EN ECUACION GENERAL: ");
scanf ("%f",&c);
printf("\nERROR DE APROXIMACION SUGERIDO: ");
scanf ("%f",&Ea);
printf("\nNUMERO DE ITERACIONES: ");
scanf ("%f",&n);
printf("\nLIMITE INICIAL: ");
scanf ("%f",&Li);
printf("\nLIMITE FINAL: ");
scanf ("%f",&Ls);
//Metodo Analitico
x1=(-b+(sqrt(pow(b,2)-(4*a*c))))/(2*a);
x2=(-b-(sqrt(pow(b,2)-(4*a*c))))/(2*a);
printf ("\nMETODO ANALITICO\n\n");
printf ("Resultados de las Raices:\n");
printf ("x1 -----> %.4f",x1);
printf ("\nx2 -----> %.4f",x2);
getch ();
//Metodo Numerico
printf ("\n\nMETODO NUMERICO\n\n");
printf ("\tIt");
printf ("\tPi");
printf ("\tError");
printf ("\tRaiz");
int cont;
for(cont=1;cont<=10;cont++)
{
pi=(Ls+Li)/2;
if((function(pi)*function(Ls))>0) Ls=pi;
else Li=pi;
error= Ls-Li;
raiz=pi;
printf("\n\t%i %f %f %f", cont,pi,error,raiz);
}
printf("\n\nRaiz Aproximada -----> %f",raiz);
printf("\nError ---------------> %f",error);
getch();
}