Vous êtes sur la page 1sur 5

Ejercicio 10

function ejercicio10()
A=input('Ingrese los datos: ');
TA=size(A);
m=TA(1);
fprintf('%s\t\t\t\t%s\t\t\t\t%s\t\t\t\t%s\n','tiempo','Error
absoluto','Error relativo','Error porcentual');
for i=2:m
tiempoActual=A(i,1);
tiempoAnterior=A(i-1,1);
errorAbsoluto=abs(tiempoActual-tiempoAnterior);
errorRelativo=errorAbsoluto/tiempoActual;
errorPorcentual=errorRelativo*100;
fprintf('%3.1f\t\t\t\t%8.2f\t\t\t\t%8.4f\t\t\t\t%8.2f%
%\n',tiempoActual,errorAbsoluto,errorRelativo,errorPorcentual);
end

ejercicio 11
function ejercicio11()
numeros=input('Ingrese la cantidad de numeros a sumar: ');
suma=0;
for i=1:numeros
fprintf('Sumando %3d:\t',i);
n=input('');
suma=suma+n;
end
b=num2str(suma);
if length(strfind(b,'.'))~= 0
b=strrep(b,'.','');
end
if length(strfind(b,'-'))~=0
b=strrep(b,'-','');
end
for i=1:length(b)
if b(1)=='0'
b(1)='';
end
if b(1)~='0'
break;
end
end
fprintf('Cifras Significativas: %4d\n',length(b));

ejercicio 12
function ejercicio12()

numeros=input('Ingrese la cantidad de numeros a sumar: ');


suma=0;
for i=1:numeros
fprintf('Sumando %3d:\t',i);
n=input('');
suma=suma+n;
end
b=num2str(suma);
if length(strfind(b,'.'))~= 0
b=strrep(b,'.','');
end
if length(strfind(b,'-'))~=0
b=strrep(b,'-','');
end
for i=1:length(b)
if b(1)=='0'
b(1)='';
end
if b(1)~='0'
break;
end
end
fprintf('La suma es: %4f\n',suma);
fprintf('Cifras Significativas: %4d\n',length(b));

ejercicio 13
function ejercicio13()
factores=input('Cuantos factores desea multiplicar: ');
producto=1;
for i=1:factores
fprintf('factor %d: ',i);
n=input(' ');
producto=producto*n;
end
b=num2str(producto);
if length(strfind(b,'.'))~= 0
b=strrep(b,'.','');
end
if length(strfind(b,'-'))~=0
b=strrep(b,'-','');
end
for i=1:length(b)
if b(1)=='0'
b(1)='';
end
if b(1)~='0'
break;
end
end
fprintf('Cifras Significativas: %4d\n',length(b));
fprintf('El producto es: %4f\n',producto);

EJERCICIO 14

function seno()
x=input('ingrese un valor para la funcion: ');
p=(x*pi)/180;
z=sin(p);
y=input(' ingrese el valor de cifras significativas: ');
maxit=input('ingrese el maximo numero iterativo: ');
es=(0.5*10^(2-y))*100;
Result=p;
eroraprox=100;
disp([blanks(7) 'terminos' blanks(10) 'resultado' blanks(9)
'errorRelativo' blanks(7) 'erroraprox']);
for iter=1:maxit
sold=Result;
Result=Result+(((1)^iter)*(p^(2*iter+1)))/factorial(2*iter+1);
errorRelativo=((z-Result)/z)*100;
erroraprox=abs(Result-sold)/Result*100;
fprintf('\t%5f\t\t\t%6f\t\t\t%6f\t\t\t%6f\n'
,iter,Result,errorRelativo,erroraprox);
if erroraprox<=es||iter>=maxit,break;
end
end

function cos()
x=input('ingrese un valor para la funcion: ');
p=(x*pi)/180;
z=cos(p);
y=input(' ingrese el valor de cifras significativas: ');
maxit=input('ingrese el maximo numero iterativo: ');
es=(0.5*10^(2-y))*100;
Result=p;
eroraprox=100;
disp([blanks(7) 'terminos' blanks(10) 'resultado' blanks(9)
'errorRelativo' blanks(10) 'erroraprox']);
for iter=1:maxit
sold=Result;
Result=Result+(((1)^iter)*(p^(2*iter+1)))/factorial(2*iter+1);
errorRelativo=((z-Result)/z)*100;
erroraprox=abs(Result-sold)/Result*100;
fprintf('\t%5f\t\t\t%6f\t\t\t%2e\t\t\t%6f\n'
,iter,Result,errorRelativo,erroraprox);
if erroraprox<=es||iter>=maxit,break;
end
end

EJERCICIO 15
function menu1()
fprintf('\t\t\t\t\t Men \n');
fprintf('\t\t 1. ngulos en radianes \n');
fprintf('\t\t 2. ngulo en sexagesimales \n');
op=input('Ingrese una opcin del men: ');
switch op
case 1
rad=input('Ingrese el ngulo: ');
x=(rad*pi)/180;
case 2
x=input('Ingrese el ngulo: ');
otherwise
fprintf('\t\t\t ERROR DE OPCIN \t\t\t\n');
end
z=sin(x);
y=input(' ingrese el valor de cifras significativas: ');
maxit=input('ingrese el maximo numero iterativo: ');
es=(0.5*10^(2-y))*100;
Result=x;
eroraprox=100;
disp([blanks(7) 'terminos' blanks(10) 'resultado' blanks(9)
'errorRelativo' blanks(7) 'erroraprox']);
for iter=1:maxit
sold=Result;
Result=Result+(((1)^iter)*(x^(2*iter+1)))/factorial(2*iter+1);
errorRelativo=((z-Result)/z)*100;
erroraprox=abs(Result-sold)/Result*100;
fprintf('\t%5f\t\t\t%6f\t\t\t%6f\t\t\t%6f\n'
,iter,Result,errorRelativo,erroraprox);
if erroraprox<=es||iter>=maxit,break;
end
end

function menu2()

fprintf('\t\t\t\t\t Men \n');


fprintf('\t\t 1. ngulos en radianes \n');
fprintf('\t\t 2. ngulo en sexagesimales \n');
op=input('Ingrese una opcin del men: ');
switch op
case 1
rad=input('Ingrese el ngulo: ');
x=(rad*pi)/180;
case 2
x=input('Ingrese el ngulo: ');
otherwise
fprintf('\t\t\t ERROR DE OPCIN \t\t\t\n');
end
z=cos(x);
y=input(' ingrese el valor de cifras significativas: ');
maxit=input('ingrese el maximo numero iterativo: ');
es=(0.5*10^(2-y))*100;
Result=x;
eroraprox=100;
disp([blanks(7) 'terminos' blanks(10) 'resultado' blanks(9)
'errorRelativo' blanks(7) 'erroraprox']);
for iter=1:maxit
sold=Result;
Result=Result+(((1)^iter)*(x^(2*iter+1)))/factorial(2*iter+1);
errorRelativo=((z-Result)/z)*100;
erroraprox=abs(Result-sold)/Result*100;
fprintf('\t%5f\t\t\t%6f\t\t\t%6f\t\t\t%6f\n'
,iter,Result,errorRelativo,erroraprox);
if erroraprox<=es||iter>=maxit,break;
end
end

Vous aimerez peut-être aussi