Documente Academic
Documente Profesional
Documente Cultură
Matriz
Vector.-unica fila
1:5:50 paso de 5 en 5
Arrays y vectores
……………….
Disp.
Imprime vectores y matrices , muestra el texto o la variable
disp(A)
disp('text')
Input
S=input('digite el valor de la distancia entre poleas[cm]:')
n=input('digite el numero de ecuaciones')
Num2str
nombre='eduardo';
edad=59;
X=[Nombre,'tendrá',num2str(Edad),'este año'];
disp(X)
fprintf
%DIGITE SU PROPIO NOMBRE
%SU EDAD RESPECTIVA
nombre=input('díganos, cual es su nombre: ','s');
edad=input('díganos, la edad que tiene: ');
fecha=input('díganos que fecha es su cumpleaños: ','s');
disp(' ')
%imprima su nombre y edad en el cw utilixando el comando FPRINTF
fprintf('mi nombre es %s, tengo la edad de %d años y mi cumpleaños es
el %s\n',nombre,edad,fecha);
clear all
clc
x=185;
fprintf('#Genero %d Hexagesimal %x real %f Notacion Cientifica
%e\t',x,x,x,x);
linspace
primer valor, ultimo valor., y cuantos valores quiero
B=linspace(10,20,2)
%8.2 g
clear all
clc
n=input('ingrese el numero de operaciones que desea ver con la
siguinte configuracion');
x=linspace(100,2000,n);
y=x/1e6+3;
z=x*1e6-5;
fprintf('\nAncho de campo,control de la precision y notacion
cientifica\n')
fprintf('\n x y z\n')
for j=1:length(x) %j , si tengo 100 operaciones voy ha tener
j=1,2,3...100
fprintf('%d %8.2f %13.2e %13.3e\n',j,x(j),y(j),z(j))
end
%backslash
%ALT + 92
%\
clear all
clc
Rmin=1;
H=0.5;
Radio=Rmin+H;
N=5;
disp(' i Radio Area Circunferencia')
for i=1:N
fprintf('\n%3i',i)
R(i)=Radio;
Area(i)=pi*R(i).^2; %el (.^)para cada valor de R elevar al
cuadrado
Circunferencia(i)=2*pi*R(i);
Radio=Radio+H;
fprintf('%10.4f %10.4f %10.4f\n',R(i),Area(i),Circunferencia(i))
end
clear all
clc
N=1;
radio=[10 20 32 40 75 85]';
while N<=6
Circunferencia=2*pi*radio;
Area=pi*radio.^2;
fprintf('cuando el radio=%3.0f\t',radio(N))
fprintf('La circunferencia es %7.3f\t',Circunferencia (N))
fprintf('y el area es %7.3f\n',Area(N))
N=N+1;
end
if
Coamndo de decisión
Terminar en END
If – 1 cod 1 bloque
1 cond 2 bloque
2 cond 3 bloque
condicion
bloque
clear all,clc
end
disp(' UNIVERSIDAD NACIONAL SAN ANTONIO ABAD DEL CUSCO
')
disp(' FACULTAD DE INGENIERIA ELECTRICA, ELECTRONICA, INFORMATICA Y
MECANICA ')
disp(' ESCUELA PROFESIONAL DE INGENIERIA MECANICA')
disp(' ')
disp(' CALCULO DE LONGITUD DE FAJA')
disp(' ')
disp(' SAICO FERNANDEZ BLADIMIR GUSTAVO - 114059')
disp('----------------------------------------------------------------
------------ ')
disp('Problema N°1')
disp(' ')
disp('se pide determinar la "LA LONGITUS DE LA FAJA" en una
transmision flexible ')
disp(' ')
disp('para lo cual usted debera:')
disp(' ')
D2=input('1°¿CUAL ES EL VALOR DEL DIAMETRO DE LA POLEA CONDUCIDA? EN
[mm] D2= ');
disp(' ')
D1=input('2°¿CUAL ES EL VALOR DEL DIAMETRO DE LA POLEA MOTRIZ? EN
[mm] D1= ');
disp(' ')
C=input('3°¿CUAL ES LA DISTANCIA ENTRE CENTROS ? EN [mm] C= ');
disp(' ')
disp('resolviendo: ')
disp(' ')
L=(2*C)+((pi/2)*(D2+D1))+((D2-D1)^2)/(4*C);
disp(['LA LONGITUD DE LA CORREA SERA IGUAL A: L=',num2str(L),'mm'])
disp(' ')
if L>2*D2;
disp(' El calculo es CORRECTO');
else
disp(' El calculo es INCORRECTO');
end
disp(' ')
disp(' Entonces usted podra proseguir el siguiente paso de su diseño')
If
Else
End
bloque
clear all
clc
x=input('digite el avalor');
if x>0
disp([num2str(x) ' es mayor a cero']);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
clc
notas=[12 14 15];
prom=mean(notas); %mean : para calcular el promedio
if prom >=13.5
disp(['paso la asignatura con ' num2str(prom)])
end
%%%%%%%%%%%%%%%%%%%%%%
clear all
clc
x=input('digite el valor de x : \n');
if x>0
disp([num2str(x) ' el valor es mayor que cero'])
else
disp([num2str(x) ' el valor es menor que cero'])
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
clc
notas=input('ingrese la nota : \n'); % ingresar notas en [12 12 15]
prom=mean(notas);
if prom>=13.5
disp([' paso la asignatura con ' num2str(prom) ' El alumno es un
caporal '])
else
disp([' perdio la asignatura con ' num2str(prom) ' Por huevon '])
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
clc
notas=input('ingrese la nota : \n'); % ingresar notas en [12 12 15]
prom=mean(notas);
if prom>=13.5
disp([' paso la asignatura con ' num2str(prom) ' El alumno es un
caporal '])
elseif (11<prom)&&(prom<13.5) % && indica que:if prom>=13.5 esta
dentro de (11<prom)&&(prom<13.5
disp([' habilita para dar recuperacion con: ' num2str(prom) ' por
chelero '])
else
disp('pierde el curso por estupida')
end
switch
Coamndo de decisión
Terminar en END
clear all,clc
disp('SENTENIA SWITCH')
disp(' ')
disp('EJEMPLO #01')
disp(' ')
disp('Generamos un conversor de unidades, trasnformando un valor de
metros a otra unidad de longitud')
disp(' ')
unidad=input('Digite la unidad a llegar:mm, cm, ft, in :\n','s');
valor=input('digite el valor a convertir: ');
switch unidad
case 'mm'
valor_f=valor*1000; %valor en milimetros
case 'cm'
valor_f=valor*100; %el valor en cm
case 'ft'
valor_f=valor*3.281; %valor en pies
case 'in'
valor_f=valor*39.37; %valor en pulgadas
otherwise
error('valor no valido')
end
disp([num2str(valor) ' metro(s) equivale ' num2str(valor_f) ' '
unidad])
For
Comando de iteración
Terminar en END
clear all, clc
for k=1:5
a=5^k
end
While
Comando de iteración
Terminar en END
clear all, clc
a=input('valor de a: ');
while a<15
disp(a);
a=a+1;
end
disp('Correcto')
-__-----------.------------------.----___________________________________--
Graficos
plot
plot(x)
……………………..
clear all, clc
x=[1 6 5 2 1]; y=[1 0 4 3 1];
plot(x,y)
titulo
clear all,clc
x=0:pi/100:2*pi;
y=sin(x);
plot(x,y,'g')
title('grafica de la funcion sin')
xlabel('x')
ylabel('sen(x)')
grid on
legend('sen(x)','location','north')
text(pi,0.5,'hola')
…………………………………….
clear all,clc
x=0:pi/100:2*pi;
y=sin(x);z=cos(x);
plot(x,y,'r',x,z,'g')
…………………………………………………………………………
clear all,clc
y=[0:0.1:10]
x=y.^2+2*y-5
plot(x,y,':ok',x,3*y,'--xy',x,y/5,':<g')
legend('grafica 1','grafica 2','grafica 3')
title('3 curvas')
xlabel('eje y')
ylabel('eje x')
………………………………………………………………}
clear all,clc
x=0:pi/100:2*pi;
y=sin(x);
plot(x,y)
grid minor
hold on
y2=cos(x);
plot(x,y2,'r:')
legend('sin','cos')
axis([0,10,-2,2])% intervalo de las coordenadas
…………………………………………………………………………………………………..
clear all,clc
x=0:pi/100:2*pi;
y=sin(x);
plot(x,y)
grid minor
hold on
y2=cos(x);
plot(x,y2,'r:')
legend('sin','cos')
axis([0,10,-2,2])% intervalo de las coordenadas
-----------------------------------------------------------------------
Subplot
clear all,clc
x=0:pi/100:2*pi;
y=sin(x);z=cos(x);
w=exp(-x*.1).*y;
v=y.*z;
subplot(2,2,1),plot(x,y)
title('grafica 1')
xlabel('eje x')
ylabel('eje y')
subplot(2,2,2),plot(x,z)
title('grafica 2')
xlabel('eje x')
ylabel('eje y')
subplot(2,2,3),plot(x,w)
title('grafica 3')
xlabel('eje x')
ylabel('eje y')
subplot(2,2,4),plot(x,v)
title('grafica 4')
xlabel('eje x')
ylabel('eje y')
……………………………………………………………………
clear all,clc
x=0:pi/100:2*pi;
y1=sin(x);y2=cos(x);
subplot(2,1,1)
plot(x,y1)
subplot(2,1,2)
plot(x,y2)
title('y=cos(x)')
xlabel('putin')
ylabel('trump')
subplot(2,1,1)
title('y=sin(x)')
xlabel('putin')
ylabel('trump')
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
clear all,clc
x=linspace(-5,2);
beta=3;
y = cos(4*pi*x).*exp(-(1+x.^beta))% el operador (.) para que la
expresion eleve a todos los valores.
plot(x,y,'r')
title('{\bf{\it g}versus{\it x}para{\it\beta}=3}')
ylabel('{\it g}_{2}')
xlabel('{\it x}')
text(1.02,-0.16,'{\it g}_2=cos(4\pi{\it x})e^{(1+{\it x}^{\beta})}')
grid on
text(1.5,0,'total')
…………………………………….
\bf negrita
\it cursiva
Analisis estadistico
clear all,clc
x=[40 33 28 25 11 21 22 17 22 19 17 16 28 26 20 15 21 20 19 24 10 29
23 34 24 33 26 14 13 18 28 23 28 21 29 24 11 31 25 18 25 26 20 34 22
30 27 32 35 39 18 29 16 37 28 29 10 34 29 18];
length(x)
sort(x)
tabulate(x)
max(x)
min(x)
sum(x)
…………………………..
figure
y=[7 12 14 15 8 4]
pie(y)
title('sectores','fontsize',30)
clear all,clc
y=[7 12 14 15 8 4]
pie(y)
title('sectores','fontsize',30)
clear all,clc
x=[40 33 28 25 11 21 22 17 22 19 17 16 28 26 20 15 21 20 19 24 10 29
23 34 24 33 26 14 13 18 28 23 28 21 29 24 11 31 25 18 25 26 20 34 22
30 27 32 35 39 18 29 16 37 28 29 10 34 29 18];
length(x)
sort(x)
tabulate(x)
max(x)
min(x)
sum(x)
figure
y=[7 12 14 15 8 4]
pie(y)
title('sectores','fontsize',3)
hist(x,6)% muestrame las muestras en 6 barras
y=[7 12 14 15 8 4]
bar(y,'r')
bar3(y,'m')
barh(y,'e')
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Polinomios
clear all,clc
p=[5 0 -1 7]
Q=roots(p)
R=poly(Q)
P=polyfit(x,y,n)%n=1 lineal .n=2............
clear all,clc
x=[10 5 12 8 6 8 4 10]% TIEMPO DE ENTRENAMIENTO
y=[9 12 8 10 13 11 12 8]%TIEMPO QUE TRADARON EN LA ACTIVIDAD
p=polyfit(x,y,1)
figure (1)
plot(x,y,'p')
hold on
plot(p)
grid on
.----------------------------------------------------------------
clear all,clc
x=[10 5 12 8 6 8 4 10];% TIEMPO DE ENTRENAMIENTO
y=[9 12 8 10 13 11 12 8];%TIEMPO QUE TRADARON EN LA ACTIVIDAD
p=polyfit(x,y,1)
figure (1)
plot(x,y,'d')
hold on
plot(p,'b')
p1=polyval(p,x)
figure (2)
plot(x,y,'p')
hold on
plot(x,p1)
grid on
9.4567