Está en la página 1de 8

#include<stdio.

h>
void main()
{
int i,j,m,q;
float a,b,c,w,h,x,y1,posicion,tope,trape1,trape2,trape3;
float t, potx,potx1,y,z,k,NL,PN,LI,LS,PLI,PLS,PN1,PLX,f1,numerador,denominador
;
float min,max,n,h1;
int metodo;
int grado;
int coeficiente;
int vec[100];
int vec1[100];
float trapecio[100];
printf("Ejercicio que determine el valor de un polinomio:\n");
do
{
printf("\n >Ingrese el grado del polinomio: \t");
scanf("%d",&grado);
}
while((grado<0)||(grado>=10));
coeficiente=grado+1;
printf("\n >Ingrese los coeficientes de menor a mayor (es decir empezando del
grado 0): \n ");
for(i=0;i<coeficiente;i++)
{
printf("\nIngrese el valor del polinomio que este en el grado %d :\t",i);
scanf("%d",&vec[i]);
}
printf("\ny= %d ",vec[0]);
for(i=1;i<coeficiente;i++)
{
if(vec[i]==0)
printf(" ");
else
{
if(vec[i]<0)
printf(" %dx^%d",vec[i],i);
if(vec[i]>0)
printf(" + %dx^%d",vec[i],i);
}
}
printf("\n Ingresar el valor inicial de la tabla:\t ");
scanf("%f",&a);
printf("\n Ingresar el valor final de la tabla:\t ");
scanf("%f",&b);
printf("\n Ingresar el incremento:\t ");
scanf("%f",&c);
printf("\nTABLA DE RAICES EXACTAS:\n");
printf(" x\t y");
w=a;
do
{
y=vec[0];
potx=a;

for(i=1;i<coeficiente;i++)
{
y=y+vec[i]*potx;
potx=potx*a;
if(y==0)
printf("\n%0.2f \t %0.2f",a,y);
}
a=a+c;
}
while(a<=b);
printf("\nElija elnumero del metodo en el cual va a evaluar el polinomio:\n1. B
isectriz \n2. Falsa Posicion \n 3. Newton\n");
do
{
scanf("%d",&metodo);
}
while((metodo<0)||(metodo>=4));
printf("\nLAS RAICES CALCULADAS DEL POLINOMIO SON\n");
if(metodo==1)
{
printf("\n\nTABLA DE RESULTADOS PARA CAMBIOS DE SIGNO:\n");
printf(" x\t y");
q=0;
do
{
y=vec[0];
potx=w;
for(i=1;i<coeficiente;i++)
{
y=y+vec[i]*potx;
potx=potx*w;
}
z=vec[0];
h=w+c;
potx=h;
for(i=1;i<coeficiente;i++)
{
z=z+vec[i]*potx;
potx=potx*h;
}
k=y*z;
if(k<0)
{
printf("\n%0.2f\t%0.2f\n",w,y);
printf("\n%0.2f\t%0.2f\n",h,z);
printf("\n LI \tP(Li) \tLS \tP(LS)\tNL \tP(NL) ");
LI=w;
LS=h;
PLI=y;
PLS=z;
do
{
NL=(LI+LS)/2;
PN=vec[0];

potx=NL;
for(i=1;i<coeficiente;i++)
{
PN=PN+vec[i]*potx;
potx=potx*NL;
}
printf("\n %0.2f \t%0.2f \t%0.2f \t%0.2f \t%0.2f
\t%0.2f",LI,PLI,LS,PLS,NL,PN);
if(PN<0)
{
PN1=PN*(-1);
}
else
{
PN1=PN;
}
if(PN==0)
{
printf("\nLa raiz exacta es %0.2f",NL);
}
if(PN*PLI>0)
{
LI=NL;
PLI=PN;
}
else
{
LS=NL;
PLS=PN;
}
}
while(PN1>=0.01);
if(PN1!=0)
printf("\nLa raiz calculada es %0.2f",NL);
}
w=w+c;
}
while(w<=b);
}

if(metodo==2)
{
printf("\n\nTABLA DE RESULTADOS PARA CAMBIOS DE SIGNO:\n");
printf(" x\t y");
do
{
y=vec[0];
potx=w;
for(i=1;i<coeficiente;i++)
{
y=y+vec[i]*potx;
potx=potx*w;

}
z=vec[0];
h=w+c;
potx=h;
for(i=1;i<coeficiente;i++)
{
z=z+vec[i]*potx;
potx=potx*h;
}
k=y*z;
if(k<0)
{
printf("\n%0.2f\t%0.2f\n",w,y);
printf("\n%0.2f\t%0.2f\n",h,z);
printf("\n LI
P(Li)
LS

\tP(LS)

NL

P(NL) ");

LI=w;
LS=h;
PLI=y;
PLS=z;
do
{
numerador=PLS*(LS-LI);
denominador=PLS-PLI;
NL=LS-(numerador/denominador);
PN=vec[0];
potx=NL;
for(i=1;i<coeficiente;i++)
{
PN=PN+vec[i]*potx;
potx=potx*NL;
}
0.2f

printf("\n %0.2f
%0.2f",LI,PLI,LS,PLS,NL,PN);
if(PN<0)
{
PN1=PN*(-1);
}
else
{
PN1=PN;
}

%0.2f

%0.2f

%0.2f

if(PN==0)
{
printf("\nLa raiz exacta es %0.2f",NL);
}

if(PN*PLI>0)
{
LI=NL;
PLI=PN;
}
else
{
LS=NL;
PLS=PN;

}
}
while(PN1>=0.01);
if(PN1!=0)
printf("\nLa raiz calculada es %0.2f",NL);
}
w=w+c;
}
while(w<=b);
}
if(metodo==3)
{
i=1;
vec1[0]=vec[1];
printf("\ny'= %d ",vec1[0]);
i++;
for(j=1;j<coeficiente-1;j++)
{
vec1[j]=vec[i]*i;
if(vec1[j]<0)
printf(" %dx^%d",vec1[j],j);
if(vec1[j]>0)
printf(" + %dx^%d",vec1[j],j);
i++;
}
m=0;
printf("\n\nTABLA DE RESULTADOS PARA CAMBIOS DE SIGNO:\n");
printf(" x\t y");
do
{
y=vec[0];
potx=w;
for(i=1;i<coeficiente;i++)
{
y=y+vec[i]*potx;
potx=potx*w;
}
z=vec[0];
h=w+c;
potx=h;
for(i=1;i<coeficiente;i++)
{
z=z+vec[i]*potx;
potx=potx*h;
}
k=y*z;
if(k<0)
{
printf("\n%0.2f\t%0.2f\n",w,y);
printf("\n%0.2f\t%0.2f\n",h,z);
printf("\nCon que valor desea evaluar el polinomio\n");
scanf("%f",&posicion);

if(posicion==w)
{
m=0;
x=w;
do
{
y=vec[0];
potx=x;
for(i=1;i<coeficiente;i++)
{
y=y+vec[i]*potx;
potx=potx*x;
}
f1=vec1[0];
potx=x;
for(j=1;j<coeficiente-1;j++)
{
f1=f1+vec1[j]*potx;
potx=potx*x;
}
x=x-(y/f1);
if(y<0)
{
y1=y*(-1);
}
else
{
y1=y;
}
m++;
}
while(y1>=0.01);
printf("\nEl valor de la raiz es en X%d = %0.3f",m,x);
}
if(posicion==h)
{
x=h;
do
{
y=vec[0];
potx=x;
for(i=1;i<coeficiente;i++)
{
y=y+vec[i]*potx;
potx=potx*x;
}
f1=vec1[0];
potx=x;
for(j=1;j<coeficiente-1;j++)
{
f1=f1+vec1[j]*potx;
potx=potx*x;
}
x=x-(y/f1);
if(y<0)

{
y1=y*(-1);
}
else
{
y1=y;
}
m++;
}
while(y1>=0.01);
printf("\nEl valor de la raiz es en X%d = %0.2f",m,x);
m=0;
}
}
w=w+c;
}
while(w<=b);
}
printf("\nIngrese el limite inferior del intervalo de integracion: ");
scanf("%f",&min);
printf("\nIngrese el limite superior del intervalo de integracion: ");
scanf("%f",&max);
printf("\nIngrese el numero de divisiones: ");
scanf("%f",&n);
h1=(max-min)/n;
printf("\nEl valor de h es %0.3f",h1);
printf("\nTABLA DE VALORES:\n");
printf(" x\t y");
q=0;
do
{
y=vec[0];
potx=min;
for(i=1;i<coeficiente;i++)
{
y=y+vec[i]*potx;
potx=potx*min;
}
printf("\n%0.3f \t %0.3f",min,y);
trapecio[q]=y;
q++;
min=min+h1;
}
while(min<=max);
for(q=1;q<n;q++)
{
tope=tope+trapecio[q];
}
trape1= trapecio[0]+trapecio[q];
trape2=(h1/2)*(trape1+(2*tope));
if(trape2<0)
{
trape3= trape2*(-1);
printf("\nEl valor del area bajo el eje x es: %0.3f",trape3);
}
else

{
trape3=trape2;
printf("\nEl valor del area es: %0.3f",trape3);
}
}

También podría gustarte