Sunteți pe pagina 1din 5

% PROGRAMA01.

M
% GRAFICO DE UNA FUNCION

clear all;close all;clc

n=input('Ingrese numero de periodos, N=');


x=0:pi/20:2*pi*n;
y=sin(x)+0.25*sin(3*x)+0.1*sin(5*x);
plot(x,y)
grid on
title('Funcion Senoidal')
xlabel('Tiempo(s)')
ylabel('Desplazamiento(m)')

% PROGRAMA02.M
% GRAFICO DE DOS FUNCION
%Nota: Cuando se graba desaparece el asteriscoi del nombre del script

clear all;close all;clc

n=input('Ingrese numero de periodos, N=');


x=0:pi/20:2*pi*n;
y=sin(x)+0.25*sin(3*x)+0.1*sin(5*x);
z=1.25*cos(x)+0.5*cos(3*x)+0.25*cos(5*x);
plot(x,y,x,z)
grid on
title('Funcion Senoidal')
xlabel('Tiempo(s)')
ylabel('Desplazamiento(m)')
legend('senoidal','cosenoidal')

% PROGRAMA03.M
% GRAFICO DE DOS FUNCION EN UNA MATRIZ GRAFICA
%Nota: Cuando se graba desaparece el asteriscoi del nombre del script
%USO DE LA FUNCION SUBPLOT: subplot(x,y,z)-x filas-y columnas-Posicion
z

clear all;close all;clc

n=input('Ingrese numero de periodos, N=');


x=0:pi/20:2*pi*n;
y=sin(x)+0.25*sin(3*x)+0.1*sin(5*x);
z=1.25*cos(x)+0.5*cos(3*x)+0.25*cos(5*x);
subplot(1,2,1) % 1 fila 2 columnas, posicion 1
plot(x,y)
grid on
title('Funcion Senoidal')
xlabel('Tiempo(s)')
ylabel('Desplazamiento(m)')
subplot(1,2,2) % 1 fila 2 columnas, posicion 2
plot(x,z)
grid on
title('Funcion Cosenoidal')
xlabel('Tiempo(s)')
ylabel('Velocidad(m/s)')
% PROGRAMA04.M
% GRAFICO DE CUATRO FUNCIONES EN UNA MATRIZ GRAFICA 2X2
%Nota: Cuando se graba desaparece el asteriscoi del nombre del script
%USO DE LA FUNCION SUBPLOT: subplot(x,y,z)-x filas-y columnas-Posicion
z

clear all;close all;clc

n=input('Ingrese numero de periodos, N=');


x=0:pi/20:2*pi*n;
y=sin(x)+0.25*sin(3*x)+0.1*sin(5*x);
z=1.25*cos(x)+0.5*cos(3*x)+0.25*cos(5*x);
w=x.^2.*sin(x.^2);
k=x+x.^2.*tan(x);
subplot(2,2,1)
plot(x,y,'r')
grid on
title('Funcion Senoidal')
xlabel('Tiempo(s)')
ylabel('Desplazamiento(m)')
subplot(2,2,2)
plot(x,z,'m')
grid on
title('Funcion Cosenoidal')
xlabel('Tiempo(s)')
ylabel('Velocidad(m/s)')
%------------------------------
subplot(2,2,3)
plot(x,w,'g')
grid on
title('Funcion W')
xlabel('Tiempo(s)')
ylabel('Aceleracion(m/s^2)')
subplot(2,2,4)
plot(x,k,'b')
grid on
title('Funcion Libre')
xlabel('Tiempo(s)')
ylabel('Altura(m)')

%PROGRAMA05.M
%Uso de for para generar una tabla de p cuadradas
clear all;close all;clc
format short
n=input('Ingrese cantidad de datos, N=');
tabla=[]; %Inicializando tabla vacia
for i=1:n
tabla=[tabla;i sqrt(i)];
end
disp(tabla) % Muestra o visualiza
plot(x,w,'g')
grid on
title('Funcion W')
xlabel('Tiempo(s)')
ylabel('Aceleracion(m/s^2)')
subplot(2,2,4)
plot(x,k,'b')
grid on
title('Funcion Libre')
xlabel('Tiempo(s)')
ylabel('Altura(m)')

%PROGRAMA06.M
%Uso de for para generar una tabla de p cuadradas
%y uso de formato de impresion fprintf
clear all;close all;clc
format short
n=input('Ingrese cantidad de datos, N=');
fprintf('\n')
fprintf('NUMERO \t RAIZ CUADRADA \t RAIZ CUBICA\n')
for i=1:n
fprintf('%4d %13.6f %13.6f\n',i,sqrt(i),i^(1/3))
end
%aadir la raiz cubica

%PROGRAMA07.m
%SERIE DE TAYLOR DEL exp(x)
% s=1+x/1!+x^2/2!+x^3/3!+x^4/4!+...+x^n/n!
close all;clear all;clc
x=input('Ingrese x(real)=');
n=input('Ingrese n(entero)}=');
s=1;
for i=1:n
term=x^i/factorial(i);
s=s+term;
end
fprintf('Suma=%18.12f \n',s)
fprintf('exp(%6.4f)=%18.12f \n',x,exp(x))
err=abs(exp(x)-s);
fprintf('Error=%18.12f \n\n',err)
% x n error
% 1 5 0.001615161792
% 1 10 0.000000027313
% 1 15 0.000000000000
% 5 5 56.996492435910
% 5 10 2.032558077444
% 5 15 0.010241731178
% 5 20 0.000012035195
% 10 5 20548.799128140050
% 10 10 9184.160680168270
% 10 15 1073.578826200173
% 10 20 34.983769141654
% 10 25 0.389433915650

%Para x ms grande se requiere ms terminos

%PROGRAMA07.m
%SERIE DE TAYLOR DEL exp(x)
% s=1+x/1!+x^2/2!+x^3/3!+x^4/4!+...+x^n/n!
close all;clear all;clc
x=input('Ingrese x(real)=');
n=input('Ingrese n(entero)}=');
s=1;
for i=1:n
term=x^i/factorial(i);
s=s+term;
end
fprintf('Suma=%18.12f \n',s)
fprintf('Exp(%6.4f)=%18.12f \n',x,exp(x))
err=abs(exp(x)-s);
fprintf('Error=%18.12f \n\n',err)
% x n error
% 1 5 0.001615161792
% 1 10 0.000000027313
% 1 15 0.000000000000
% 5 5 56.996492435910
% 5 10 2.032558077444
% 5 15 0.010241731178
% 5 20 0.000012035195
% 10 5 20548.799128140050
% 10 10 9184.160680168270
% 10 15 1073.578826200173
% 10 20 34.983769141654
% 10 25 0.389433915650

%Mostrar el error en tabla


for j=1:8
s=1;
a=j*n;
for i=1:a
term=x^i/factorial(i);
s=s+term;
end
error=abs(exp(x)-s);
fprintf('%4d %13d %13.6f \n',x,a,error)
end

%PROGRAMA08.m
%SERIE DE TAYLOR DEL exp(x)
% s=1+x/1!+x^2/2!+x^3/3!+x^4/4!+...+x^n/n!
%Evalua hasta que el term<TOL
clc;clear all
x=input('Ingrese x(real)=');
TOL=input('Ingrese TOL(real)=');
s=1;
for i=1:1000
term=x^i/factorial(i);
s=s+term;
if abs(term)<TOL
break %salir del for
end
end
fprintf('Suma=%18.12f \n',s)
fprintf('Exp(%6.4f)=%18.12f \n',x,exp(x))
err=abs(exp(x)-s);
fprintf('Error=%18.12f \n\n',err)
fprintf('Numero de terminos = %4d\n',i)
% x TOL err NumTerms
% 1 1e-10

%PROGRAMA08.m
%SERIE DE TAYLOR DEL exp(x)
% s=1+x/1!+x^2/2!+x^3/3!+x^4/4!+...+x^n/n!
%Evalua hasta que el term<TOL
clc;clear all
x=input('Ingrese x(real)=');
TOL=input('Ingrese TOL(real)=');
s=1;
i=0;
term=1;
while (abs(term)>TOL)
i=i+1;
term=x^i/factorial(i);
s=s+term;
end
fprintf('Suma=%18.12f \n',s)
fprintf('Exp(%6.4f)=%18.12f \n',x,exp(x))
err=abs(exp(x)-s);
fprintf('Error=%18.12f \n\n',err)
fprintf('Numero de terminos = %4d\n',i)
% x TOL err NumTerms
% 1 1e-10

% Archivo: serietaylor.m
% funcion: serietaylor
function [s,err,NumIte]=serietaylor(x,TOL)
s=1;
for i=1:1000
term=x^i/factorial(i);
s=s+term;
if abs(term)<TOL
break %salir del for
end
end
err=abs(exp(x)-s);
NumIte=i;

S-ar putea să vă placă și