Está en la página 1de 2

disp('determinar la raiz de un polimonio')

disp('gx^r+fx^r-1+ax^r-1+bx+c=0')
%g=input('ingresar valor coeficiente de x^4= ')
%f=input('ingresar valor coeficiente de x^3= ')
%a= input('ingresar valor coeficiente de x^2= ')
%b= input('ingresar valor coeficiente de x^1= ')
%c= input('ingresar valores del termino independiente c= ')
%ingresar en el intervalo (xi,x,xf)
%xi= input('digite el inicio del intervalo= ')
%xf= input('digite el final del intervalo= ')
%ingresar la toleracion para cuando f(x) se proxime a 0
%tol= input('ingrese el valor de la toreancia= ')
%ingresar el numero de veces que se repite el proceso
%n= input('ingrese el valor n= ')
%ingresar el valor del incremento inc=((xf-xi)/(n))
%inc = ((xf-xi)/n)
disp('determinamos si es factible hallar una raiz')
%comparamos si fxi y fxf son de signos contrarios
g=4
f=3
a=1
b=-8
c=14
r=4
xi= 1.52
xf= 2.07
tol= 0.01
inc= 0.01
n=10

if r==4
fxi= g*xi^4+f*xi^3+a*xi^2+b*xi+c
fxf= g*xf^4+f*xf^3+a*xf^2+b*xf+c
else if r==3 g==0
fxi= f*xi^3+a*xi^2+b*xi+c
fxf= f*xf^3+a*xf^2+b*xf+c
else if r==2 f==0
fxi= a*xi^2+b*xi+c
fxf= a*xf^2+b*xf+c
else if r==1 a==0
fxi= b*xi+c
fxf= b*xf+c
end
end
end
end
%comparar que fxi*fxf<0
if (fxi*fxf)<0
disp('existe una solucion')
else
disp('no hay solucion')
end
%buscamos solucion .
for i=1:n
xi
i
if r==4
r
fxi= g*xi^4+f*xi^3+a*xi^2+b*xi+c
fxf= g*xf^4+f*xf^3+a*xf^2+b*xf+c
else if r==3 g==0
r
fxi= f*xi^3+a*xi^2+b*xi+c
fxf= f*xf^3+a*xf^2+b*xf+c
else if r==2 f==0
r
fxi= a*xi^2+b*xi+c
fxf= a*xf^2+b*xf+c
else if r==1 a==0
r
fxi= b*xi+c
fxf= b*xf+c
end
end
end
end

if abs(fxi)< tol
disp('la raiz es ')
xi
else
disp('intente de nuevo ')
xi= xi+inc
end
end

d= b^2-4*a*c
if d>=0
disp ('real')
x1=((-b+(b^2-4*a*c)^0.5)/(2*a))
x2=((-b-(b^2-4*a*c)^0.5)/(2*a))
else if b==0
disp ('imaginario')
x1=((((b^2-4*a*c))^0.5)/(2*a))
x2=-((((b^2-4*a*c))^0.5)/(2*a))
else
disp('complejo')
x1=((-b+(b^2-4*a*c)^0.5)/(2*a))
x2=((-b-(b^2-4*a*c)^0.5)/(2*a))
end
end

También podría gustarte