Documentos de Académico
Documentos de Profesional
Documentos de Cultura
00 0 Lenguaje Matlab Nivel 1 2014 1
00 0 Lenguaje Matlab Nivel 1 2014 1
:
Ejemplo Sean los vectores
1
= 1,3, 2 y
2
= 4,1,5
=
1
2
>>c = dot(v1,v2)
Producto interno :
Matrices especiales
eye(n) es la matriz identidad de orden n.
ones(m,n) es una matriz m x n de 1s.
zeros(m,n) es una matriz m x n de 0s.
=
1 0 0
0 1 0
0 0 1
=
1 1 1
1 1 1
1 1 1
=
0 0 0
0 0 0
0 0 0
Ejemplo
Ejemplo
Ejemplo
>>P = eye(3)
>>Q = ones(3,3)
>>R = zeros(3,3)
Estructuras de control
Estructuras
de control
Selectiva
Selectiva switch
Condicional if
Repetitiva
Bucle for
Bucle while
Funciones
function [out1,out2] = algorithm(in1,in2)
declaration line
documentation
reserved word
output arguments
identifier
input arguments
implementation
%
% algorithm :
%
% INPUT
% in1 :
% in2 :
% OUTPUT
% out1 :
% out2 :
%
Grficos 1D
x = linspace(-4*pi,4*pi,100);
-15 -10 -5 0 5 10 15
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
y = sin(x)./x;
figure
plot(x,y,b.-)
x = linspace(-pi,pi,100);
-4 -3 -2 -1 0 1 2 3 4
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Superposicin de grficos
y1 = sin(x);
figure
plot(x,y1,b.-,x,y2,r.-)
y2 = cos(x);
x = linspace(-pi,pi,100);
-4 -3 -2 -1 0 1 2 3 4
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
y1 = sin(x); y2 = cos(x);
figure
hold on
plot(x,y1,b.-), plot(x,y2,r.-)
hold off
x1 = linspace(-pi,pi,100);
-4 -3 -2 -1 0 1 2 3 4
-1
-0.5
0
0.5
1
-4 -3 -2 -1 0 1 2 3 4
-1
-0.5
0
0.5
1
x2 = linspace(-pi,pi,200);
y1 = sin(x1); y2 = cos(x2);
figure
subplot(2,1,1),plot(x1,y1,b-)
subplot(2,1,2),plot(x2,y2,r-)
t1 = linspace(-pi,pi,100);
t2 = linspace(-pi,pi,200);
x = sin(x1);
v = cos(x2);
figure
subplot(2,1,1)
title(Posicion)
plot(t1,x,b-)
xlabel(t),ylabel(x),grid
subplot(2,1,2)
title(Velocidad)
plot(t2,v,r-)
xlabel(t),ylabel(v),grid
-4 -3 -2 -1 0 1 2 3 4
-1
-0.5
0
0.5
1
Posicion
t
x
-4 -3 -2 -1 0 1 2 3 4
-1
-0.5
0
0.5
1
Velocidad
t
v