You are on page 1of 4

METODO DE RACES MULTIPLES

CODIGO MATLAB:

disp('RAICES MULTIPLES');
fprintf('\n CLCULO DE LA RAZ DE UNA ECUACIN POR EL MTODO DE RAICES
MULTIPLES \n\n');
f=input('ingrese la funcion: ','s');
f=inline(f);
fp=input('Ingrese la derivada de la funcion: ','s');
fp=inline(fp);
fpp=input('Ingrese la segunda derivada de la funcion: ','s');
fpp=inline(fpp);
xi=input('Escriba el punto de inicio: ');
tol=input('Ingrese el porcentaje (%) de error: ');
m=input('Ingrese el numero de iteraciones: ');
fx=f(xi);
fpx=fp(xi);
fppx=fpp(xi);
denominador=(power(fpx,2)-fx*fppx);
i=1;
error=tol+1;
fprintf('\n m x f(x) \n')
while i<=m && fx~=0 && error>tol && denominador~=0
x=xi-(fx*fpx)/denominador;
fx=f(x);
fpx=fp(x);
fppx=fpp(x);
denominador=(power(fpx,2)-fx*fppx);
fprintf('%1.0f %10.10f %10.10f %10.10f \n',i,x,f(x))
error=abs(x-xi);
xi=x;
i=i+1;
end

if fx==0
fprintf('\n La raz aproximada es: %1.10f \n\n',xi)
else if error<tol
fprintf('\n %1.10f es una aproximacion a la raiz con un error
maximo de %1.10f \n',xi,tol)
else
fprintf('\n El metodo fallo en %0.0f iteraciones \n\n',n)
end
end
RESULTADO 1:

RESULTADO 2:
REGRESIN POR MNIMOS CUADRADOS (REGRESIN LINEAL SIMPLE)

CODIGO MATLAB:

clear all;
clc;
fprintf('METODO DE REGRESION LINEAL \n\n');
n=input('Numero de muestras: ');
for i=1:n
x(1,i)=input('Ingrese los valores de x: ');
end
fprintf('\n');
for i=1:n
y(1,i)=input('Ingrese los valores de y: ');
end
x
y
plot(x,y)
grid
xlabel('x');ylabel('y')
pause
a=0;
for i=1:n
a=a+x(1,i)*y(1,i);
end
b=0;
for i=1:n
b=b+x(1,i)*x(1,i);
end

c=0;
for i=1:n
c=c+x(1,i);
end

e=0;
for i=1:n
e=e+y(1,i);
end

d=0;
d=c/n;
f=0;
f=e/n;
a1=(n*a-c*e)/(n*b-c*c);
a0=f-a1*d;
clc;
fprintf('La ecuacion obtenida es: \n\n');
fprintf(' y = %d + %d x',a0,a1);

for i=1:n
y(1,i)=a0+a1*x(1,i);
end
fprintf('\n\n Presione enter para ver la nueva grafica\n\n');
pause
%Grafica con los Datos Ajustados
plot(x,y)
grid
xlabel('x');ylabel('y')
pause

RESULTADOS:

EJEMPLO N1

EJEMPLO N2

You might also like