Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Funcion: clc
Nos ayuda a limpiar la pantalla llena de calculos anteriores, esta funcion no borra los datos
alamcenados en variables.
Funcion: Clear
Esta funcion es capaz de eliminar las variables globales y sus contenidos, por ello debe usarse
con sumo cuidado.
DEFINIENDO MATRICES:
0
5
9
7
6
1
4
4
8
3
5
9
MATRICES ESPECIALES
MATRIZ DE UNOS
>> ones(5)
ans =
1
MATRIZ DE CEROS
>> zeros(5)
ans =
0
MATRIZ COLUMNA
>> q=[1;5;5;8;2]
q=
1
5
5
8
2
MATRIZ FILA
>> q=[1 2 3 5 4]
1
MATRIZ TRANSPUESTA
>> M=[1 4 5 8 9;5 7 4 1 3]
>> M'
M=
1
ans =
1
4
5
8
9
5
7
4
1
3
MATRIZ INVERSA
Q=
4 -5
5 6
1 1
-1 2
7 8
6
8
5
4
9
7
3
8
1
1
8
7
7
6
3
>> inv(Q)
ans =
0.0417
-0.1250
0.0833
-0.0417
0.0000
0.4006
0.1800
-0.6047
-0.0624
0.4203
-0.1282
0.0610
0.0624
0.1959
-0.1159
-0.2790
-0.0761
0.3116
-0.1123
-0.0435
-0.1886
-0.0767
0.4199
0.0244
-0.2899
6
8
5
4
9
7
3
8
1
1
8
7
7
6
3
>> det(Q)
ans =
4968
>> Q^2
ans =
46
104
55
51
97
34
81
78
71
48
114
193
134
88
182
76 105
127 177
65 119
38 58
149 190
>> Q.^2
ans =
16
25
1
1
49
25
36
1
4
64
36 49 64
64 9 49
25 64 49
16 1 36
81 1 9
>> Q^-1
ans =
0.0417
-0.1250
0.0833
-0.0417
0.0000
0.4006
0.1800
-0.6047
-0.0624
0.4203
-0.1282
0.0610
0.0624
0.1959
-0.1159
-0.2790
-0.0761
0.3116
-0.1123
-0.0435
-0.1886
-0.0767
0.4199
0.0244
-0.2899
>> Q.^-1
ans =
0.2500
0.2000
1.0000
-1.0000
0.1429
-0.2000
0.1667
1.0000
0.5000
0.1250
0.1667
0.1250
0.2000
0.2500
0.1111
0.1429
0.3333
0.1250
1.0000
1.0000
0.1250
0.1429
0.1429
0.1667
0.3333
OPERACIONES ESPECIALES
W=
10
20
13
45
36
42
15
>> A=2*pi./W
>> W.^2
>> 1./W
A=
ans =
ans =
0.6283
0.3142
0.4833
0.1396
0.1745
0.1496
0.4189
100
400
169
2025
1296
1764
225
0.1000
0.0500
0.0769
0.0222
0.0278
0.0238
0.0667
-1
>> Q(1,1)
ans =
4
>> Q(i,j) Elemento de la fila i y de la columna j
Si desearamos manipular una fila o una columna de una matriz , procederiamos de la siguiente
forma:
>> Q(:,1)
>> Q(:,2)
>> Q(1,:)
ans =
ans =
ans =
4
5
1
-1
7
-5
6
1
2
8
4 -5
>> Q(5,:)
ans =
7
>> [s,d]=eig(R)
s=
R=
-4
-5
-1
14
13
0
0
0
2
0
0
1.0000
0.7974 0.6667
0.5696 0.3333
-0.1994 -0.6667
d=
2.0000
0
0
0
6.0000
0
0
0
3.0000
GRAFICO DE FUNCIONES EN 2D
>> x=0:0.01:2;
>> y=sin(pi*x/2);
>> plot(x,y)
Para generar un dibujo adicional en el mismo lienzo. Usaremos la funcion Hold on.
>> x=0:0.01:2;
>> y=sin(pi*x/2);
>> plot(x,y)
>> hold on
>> y1=x.^2-2*x;
>> plot(x,y1)
>> x=0:0.01:1;
>> y=sin(pi*x);
>> y1=cos(pi*x)/3;
>> plot(x,y)
>> hold on
>> plot(x,y1)
>> x=0:0.01:1;
>> y=sin(pi*x);
>> y1=cos(pi*x)/3;
>> plot(x,y)
>> figure(2)
>> plot(x,y1)
>> hold on
>> plot(x,y,'r--')
>> x=0:0.01:2;
>> y=x.*exp(-x.^2);
>> plot(x,y)
>> grid on
>> xlabel('TIEMPO(s)');
>> ylabel('FUERZA(Ton)');
>> title('FUERZA VS TIEMPO')
>> ezplot('x^2-x*sin(x)')
>> theta=-pi:0.01:pi;
>> r=2-4*cos(theta);
>> polar(theta,r)
EJEMPLOS:
FUNCION LISPACE
>> linspace(0,1,6)
ans =
0 0.2000 0.4000 0.6000 0.8000 1.0000
>> linspace(0,1,3)
ans =
0 0.5000 1.0000
>> x=linspace(0,1,7)
x=
0 0.1667 0.3333 0.5000 0.6667 0.8333 1.0000
GRAFICO DE FUNCIONES EN 3D
Para dibujar grficos de funciones de dos variables z = f(x; y), al igual que para
funciones de una variable, en primer lugar hay que generar tablas de valores para
las variables x e y, en realidad, ahora lo que tenemos que hacer es generar un
mallado sobre un rectngulo del plano XY . Para eso se utiliza el comando
meshgrid.
>> x=-2:0.01:2;
>> y=-2:0.01:2;
>> [x,y]=meshgrid(x,y);
>> z=exp(-x.^2-y.^2);
>> plot3(x,y,z)
>> x=-2:0.1:2;
>> y=-2:0.1:2;
>> [x,y]=meshgrid(x,y);
>> z=exp(-x.^2-y.^2);
>> figure(2)
>> mesh(x,y,z)
>> x=-2:0.1:2;
>> y=-2:0.1:2;
>> [x,y]=meshgrid(x,y);
>> z=exp(-x.^2-y.^2);
>> figure(3)
>> surf(x,y,z)
>> x=-2:0.1:2;
>> y=-2:0.1:2;
>> [x,y]=meshgrid(x,y);
>> z=exp(-x.^2-y.^2);
>> figure(4)
>> contour(x,y,z,10)
>> x=-2:0.1:2;
>> y=-2:0.1:2;
>> [x,y]=meshgrid(x,y);
>> z=exp(-x.^2-y.^2);
>> figure(5)
>> contourf(x,y,z,10)
>> contourf(x,y,z,10),colorbar
PROGRAMACION EN MATLAB
PROGRAMACION EN MATLAB
Ejemplo 1: Calcular la suma de los n primeros trminos de la sucesin 1, 2x, 3x^2,
4x^3, ...
%PRIMER EJEMPLO DE PROGRAMACION
%UNASAM 2015
clear;
clc;
n=input('INGRESE LA CANTIDAD DE DATOS:');
x=input('INGRESE EL VALOR DE X:');
r=1;
for i=2:n
r=r+i*x^(i-1);
end
fprintf('EL RESULTADO ES: %.3f\n',r);