Documentos de Académico
Documentos de Profesional
Documentos de Cultura
Clases LengProg
Clases LengProg
LENGUAJE DE
PROGRAMACIÓN
(5 4 1 2 2 1)
INTRODUCCIÓN
Lenguaje de Programación
MACROCOMPETENCIA GENÉRICAS
Pensamiento
Comunicación
Crítico
ESTUDIANTE
Emprendimiento
Responsabilidad
y Trabajo en
Social
Equipo
Interdisciplinario
1/14
INTRODUCCIÓN
Lenguaje de Programación
NIVELES DE ADQUISICIÓN
Incorporar en
Nivel 3 Hacer las acciones
profesionales
Conductual
2/14
INTRODUCCIÓN
Lenguaje de Programación
PENSAMIENTO CRÍTICO
3/14
INTRODUCCIÓN
Lenguaje de Programación
COMUNICACIÓN
4/14
INTRODUCCIÓN
Lenguaje de Programación
5/14
INTRODUCCIÓN
Lenguaje de Programación
RESPONSABILIDAD SOCIAL
6/14
INTRODUCCIÓN
Lenguaje de Programación
ENFRENTÁNDOSE A UN PROBLEMA
PROBLEMA RESULTADOS
¿Qué información?
INFORMACIÓN
Pensamiento
Crítico
¿Qué datos?
Responsabilidad
Comunicación Social
Pensamiento
Crítico
Trabajo en
Comunicación
Equipo
SOLUCIÓN
Responsabilidad VERIFICAR
Social Funcionamiento
ALGORITMO Resultados
DISEÑO
Entrada
Proceso CODIFICAR
Salida PROGRAMA Lenguaje
7/14
INTRODUCCIÓN
Lenguaje de Programación
Memoria
Central Almacenamiento
Pantalla secundario
Disco duro
Teclado
Compact Disk
Mouse
Unidad Central
de Proceso Cinta Magnética
Impresoras Dispositivo
Almacenamiento
masivo
8/14
INTRODUCCIÓN
Lenguaje de Programación
LENGUAJES DE PROGRAMACIÓN
SENTENCIA
Cadena de comandos,
expresiones y símbolos que
permiten ejecutar una acción
COMANDOS SINTAXIS
Definen la acción a Reglas de escritura
ejecutar del lenguaje
9/14
INTRODUCCIÓN
Lenguaje de Programación
10/14
INTRODUCCIÓN
Lenguaje de Programación
VENTAJA DESVENTAJAS
Transferencia a memoria ●
Codificación compleja
sin necesidad de traducción ●
Fiabilidad baja
●
Difícil verificación, actualización
●
Dependientes del procesador
Velocidad de ejecución
superior a cualquier otro
lenguaje
11/14
INTRODUCCIÓN
Lenguaje de Programación
VENTAJAS DESVENTAJAS
Tiempo de formación de
Mayor tiempo para obtener
programadores corto el programa ejecutable
Escritura basada en reglas
Mayor utilización de la memoria
sintácticas similares al
Mayor tiempo de ejecución
lenguaje humano
Fácilmente modificables
Bajo costo de programación
Transportable
12/14
INTRODUCCIÓN
Lenguaje de Programación
Programa Fuente
Compilador
Programa objeto
Enlazador
(link)
Programa
Ejecutable
13/14
INTRODUCCIÓN
Lenguaje de Programación
Programa Fuente
Interprete
Traducción y Ejecución
Línea a Línea
14/14
ALGORITMOS
Micro Clase
MOTIVACIÓN
Cocer un huevo
1/16
ALGORITMOS
Micro Clase
OBJETIVO
2/16
ALGORITMOS
Micro Clase
DEFINICIÓN
Características
3/16
ALGORITMOS
Micro Clase
CONSTRUCCIÓN
4/16
ALGORITMOS
Micro Clase
REPRESENTACIÓN
●
Independiente del lenguaje de programación
●
Visualización clara de la secuencia de acciones
●
Se utilizan palabras y símbolos normalizados
para especificar las diferentes acciones que pueden
ejecutarse en un computador
5/16
ALGORITMOS
Micro Clase
SIMBOLOGÍA
CONTROL
Iniciar
algoritmo INICIO
Terminar
algoritmo FIN
6/16
ALGORITMOS
Micro Clase
SIMBOLOGÍA
Operación
Ingresar Ingresar C=5*sen(x)*(h1/Ti)
aritmética
datos Radio, Ang
7/16
ALGORITMOS
Micro Clase
SIMBOLOGÍA
SELECTIVA SELECTIVA
F Expresión V Expresión
lógica numérica
Selección Repetición
lógica numérica
V1 V2 V3 V4
8/16
ALGORITMOS
Micro Clase
SIMBOLOGÍA
REPETITIVA REPETITIVA
K > Vf F
K=Vi, Inc, Vf Expresión lógica
V
Repetición Repetición
definida condicional
9/16
ALGORITMOS
Micro Clase
PROBLEMA
INICIO
FIN
10/16
ALGORITMOS
Micro Clase
PROBLEMA
11/16
ALGORITMOS
Micro Clase
PROBLEMA: Análisis
12/16
ALGORITMOS
Micro Clase
●
Entrada ➔
Diámetro
●
Proceso ➔
Evaluación analítica:
Perímetro =π⋅Diámetro
Área = π⋅Diámetro2
4
➔
Perímetro
●
Salida ➔
Área
13/16
ALGORITMOS
Micro Clase
INICIO
Leer
D
P=3.14*D
A=3.14/4*D*D
Imprimir
“Perímetro=”,P
“Área=”,A
FIN
14/16
ALGORITMOS
Micro Clase
15/16
ALGORITMOS
Micro Clase
PROBLEMA PROPUESTO
16/16
HERRAMIENTAS DE PROGRAMACIÓN
Lenguaje de Programación
EXPRESIONES ARITMÉTICAS
+ Suma
- Resta ENTEROS ENTERO
* Multiplicación O O
/ División REALES REAL
**, ^ Exponenciación
Reglas de Prioridad
Exponenciación: **, ^
Multiplicación, División: * /
Suma, Resta: + -
(),
1/13
HERRAMIENTAS DE PROGRAMACIÓN
Lenguaje de Programación
EXPRESIONES LÓGICAS
Distinto ~=
2/13
HERRAMIENTAS DE PROGRAMACIÓN
Lenguaje de Programación
FUNCIONES INTERNAS
3/13
HERRAMIENTAS DE PROGRAMACIÓN
Lenguaje de Programación
OPERACIÓN DE ASIGNACIÓN
Variable = Expresión
Paso 2
Transfiere valor Posición de memoria
temporal
4/13
HERRAMIENTAS DE PROGRAMACIÓN
Lenguaje de Programación
OPERACIÓN DE ASIGNACIÓN
b b 2 4 ac
x1 siendo: a=2.9; b=8.0; c=-6.2
2a
a b c x1 temp
2.9 8.0 -6.2 0.63 0.63
Procesador
X1=(-b+sqrt(b^2-4*a*c))/(2*a)
5/13
HERRAMIENTAS DE PROGRAMACIÓN
Lenguaje de Programación
OPERACIÓN DE ASIGNACIÓN
6/13
HERRAMIENTAS DE PROGRAMACIÓN
Lenguaje de Programación
TIPOS DE DATOS
Numéricos Entero
Real
Simples
Carácter
No numéricos Booleano
Usuario
Tipos
de Vector
Estáticas Matriz
datos
Internas
Lista
Pila
Dinámicas
Cola
Estructuras Arbol
de datos
Secuencial
Archivos Directo
Indexado
Externas
Bases de datos
7/13
HERRAMIENTAS DE PROGRAMACIÓN
Lenguaje de Programación
PROBLEMA PROPUESTO
8/13
HERRAMIENTAS DE PROGRAMACIÓN
Lenguaje de Programación
PROBLEMA PROPUESTO
INICIO
LEER a, b
no si
a>b
IMPRIMIR IMPRIMIR
b es el mayor a es el mayor
FIN
9/13
HERRAMIENTAS DE PROGRAMACIÓN
Lenguaje de Programación
PROBLEMA PROPUESTO
10/13
HERRAMIENTAS DE PROGRAMACIÓN
Lenguaje de Programación
PROBLEMA PROPUESTO
INICIO
LEER a, b, c
no si
a>b
no b>c si no si
a>c
FIN
11/13
HERRAMIENTAS DE PROGRAMACIÓN
Lenguaje de Programación
PROBLEMAS PROPUESTOS
Problema 1
Problema 2
12/13
HERRAMIENTAS DE PROGRAMACIÓN
Lenguaje de Programación
PROBLEMAS PROPUESTOS
Problema 3
Problema 4
13/13
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
INTRODUCCIÓN
Concepto de Programa
En esencia, un programa es
un medio para conseguir un fin.
¿Cuál es el fin?
1/26
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
ASIGNACIÓN NUMÉRICA
Diagrama de flujo
Código Matlab
a pi/2.54 a=pi/2.54;
u 45.76a u=45.76*a;
t 4a/pi t=4*a/pi;
y 54.9 y=54.9;
C 10*cos(a)+(u+5t)/(3y) c=10*cos(a)+(u+5*t)/(3*y)
y y+1 y=y+1;
2/26
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
ASIGNACIÓN ALFANUMÉRICA
Diagrama de flujo
Código Matlab
nombre “Pedro” nombre=‘Pedro’;
Q1 nombre Q1=nombre;
3/26
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
LECTURA
Diagrama de flujo
Código Matlab
Numérica
Leer Radio=input('Ingrese Radio = ');
Radio, Ang Ang=input('Ingrese Angulo = ');
4/26
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
ESCRITURA
Diagrama de flujo
Código Matlab
Diagrama de flujo
Código Matlab
IMPRIMIR
“El color es:”,P fprintf (1,'\n El color es: %s',P);
5/26
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
ESTRUCTURA SECUENCIAL
clc
INICIO clear all
%
% Lectura de datos
LEER % ----------------
a,b a=input('Ingresar valor 1:');
b=input('Ingresar valor 2:')
%
S a+b % Cálculos
% --------
P a*b
S=a+b;
P=a*b;
IMPRIMIR %
“La suma es:”,S % Impresión de resultados
“El producto es:”,P % -----------------------
fprintf(1,'\n La suma es : %f’,S);
fprintf(1,'\n El productos es: %f’,P);
FIN %
close all
6/26
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
ESTRUCTURAS SELECTIVAS
- Simples
- Dobles
- Múltiples
7/26
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
Diagrama de flujo
Código Matlab
%
Expresión F
if (Expresión lógica)
lógica
Conjunto
de
V sentencias
end
Conjunto de %
sentencias
8/26
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
PROBLEMA 1
9/26
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
Diagrama de flujo
Código Matlab
%
if (Expresión lógica)
V Expresión F Conjunto 1
lógica de
sentencias
else
Conjunto 2
Conjunto 1 Conjunto 2
de
de sentencias de sentencias
sentencias
end
%
10/26
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
PROBLEMA 2
11/26
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
Diagrama de flujo
Código Matlab
F
Exp 1
%
V if (Exp 1)
Sentencias 1
Sentencias 1
elseif (Exp 2)
F
Sentencias 2
Exp 2 elseif (Exp n)
V Sentencias n
Sentencias 2 else
Sentencias m
end
Exp n F %
V
Sentencias n Sentencias m
12/26
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
PROBLEMA 3
13/26
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
%
switch (Expr. arit.)
Expresión case V1
Aritmética Sentencias V1
case V2
Sentencias V2
V1 case Vn
Otro
V2 Vn Sentencias Vn
otherwise
Sentencias Sentencias Sentencias Sentencias
Sentencias Otro
V1 V2 Vn Otro
end
%
14/26
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
PROBLEMA 4
15/26
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
F
Exp. 1
Código Matlab
V %
Sentencias 1 if (Exp. 1)
Sentencias 1
F if (Exp. 2)
Exp. 2
if (Exp. 3)
V Sentencias 3
F V else
Exp. 3 Sentencias 2
Sentencias 2 Sentencias 3 end
end
Sentencias 4
end
%
Sentencias 4
16/26
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
PROBLEMA 5
17/26
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
PROBLEMA 6
18/26
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
ESTRUCTURA REPETITIVAS
- Mientras
- Repetir
- Para
19/26
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
Diagrama de flujo
Conjunto de
sentencias
F Expresión
Lógica
20/26
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
Diagrama de flujo
Código Matlab
Expresión F %
Lógica while (Expresión Lógica)
V
Conjunto
de
Conjunto de sentencias
sentencias
end
%
21/26
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
PROBLEMA 7
22/26
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
%
for a=Vi:Inc:Vf
a > Vf
a=Vi, Inc, Vf
Conjunto
de
sentencias
Conjunto de
sentencias end
%
23/26
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
PROBLEMA 8
24/26
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
Diagrama de flujo
Código Matlab
a > Vf %
a=Vi, Inc, Vf
for a=Vi:Inc:Vf
Sentencias 1 Sentencias 1
25/26
ESTRUCTURAS DE PROGRAMACIÓN
Lenguaje de Programación
ESTRUCTURA REPETITIVAS
PROBLEMA 9
26/26
ESTRUCTURAS DE DATOS
Lenguaje de Programación
ARREGLOS
1/15
ESTRUCTURAS DE DATOS
Lenguaje de Programación
Memoria
Notas
(1) 5.3
Notas(1)=input(‘……’);
Notas(2)=input(‘……’);
(2) 4.7
.
. for i=1:n
Notas(i)=input(‘……’);
(i) 2.1 end
.
.
(n) 6.0
2/15
ESTRUCTURAS DE DATOS
Lenguaje de Programación
Memoria Pantalla
Lab 1 = 5.3
Notas Lab 2 = 4.7
(i) 2.1
.
.
(n) 6.0
Pantalla
Lab 1 = 5.3
Lab 2 = 4.7
.
for i=1:n .
fprintf(1,’\n Lab %2.0f = %3.1f’,i,Notas(i)); Lab i = 2.1
.
end .
Lab n = 6.0
3/15
ESTRUCTURAS DE DATOS
Lenguaje de Programación
Memoria
(1) 5.3
Pantalla
(2) 4.7 Promedio = 4.9
P=0;
. for k=1:n
. P=P+Notas(k);
end
(i) 2.1
P=P/n;
. fprintf(1,’\n Promedio = %3.1f’,P);
.
(n) 6.0
4/15
ESTRUCTURAS DE DATOS
Lenguaje de Programación
clear all
clc Memoria Pantalla
% Ingrese N° de notas: _
n=input(‘Ingrese N° de notas: ’); Notas Ingrese Nota 1: _
Ingrese Nota 2: _
for i=1:n (1) .
5.3
fprintf(1,’\n Ingrese Nota %0.0f: ’,i); .
.
Notas(i)=input(‘’); (2) 4.7 Ingrese Nota n: _
end
% (3) 5.7
P=0;
for k=1:n Pantalla
(4) 2.1
P=P+Notas(k); Promedio = 5.6
end
(5) 4.1
P=P/n;
%
(6) 6.0
clc
fprintf(1,’\n Promedio = %3.1f’,P);
close all
5/15
ESTRUCTURAS DE DATOS
Lenguaje de Programación
PROBLEMA
6/15
ESTRUCTURAS DE DATOS
Lenguaje de Programación
PROBLEMA
7/15
ESTRUCTURAS DE DATOS
Lenguaje de Programación
ARREGLOS BIDIMENSIONALES
8/15
ESTRUCTURAS DE DATOS
Lenguaje de Programación
ARREGLOS BIDIMENSIONALES
9/15
ESTRUCTURAS DE DATOS
Lenguaje de Programación
PROBLEMA
10/15
ESTRUCTURAS DE DATOS
Lenguaje de Programación
PROBLEMA
11/15
ESTRUCTURAS DE DATOS
Lenguaje de Programación
PROBLEMA
12/15
ESTRUCTURAS DE DATOS
Lenguaje de Programación
PROBLEMA
13/15
ESTRUCTURAS DE DATOS
Lenguaje de Programación
PROBLEMA
Ingresar la matriz
Imprimir la matriz en pantalla
Desplazar todas las columnas una posición hacia la derecha
Desplazar todas las filas una posición hacia abajo
Desplazar todas columnas hacia la derecha y todas las filas hacia abajo
14/15
ESTRUCTURAS DE DATOS
Lenguaje de Programación
PROBLEMA
15/15
PROGRAMACIÓN ESTRUCTURADA
Lenguaje de Programación
TÉCNICAS DE PROGRAMACIÓN
1/10
PROGRAMACIÓN ESTRUCTURADA
Lenguaje de Programación
ESTRUCTURA GENERAL
Módulo
principal
Módulo 3.1
Módulo 1.1 Módulo 1.2 Módulo n.1
Módulo 3.1.2.1
2/10
PROGRAMACIÓN ESTRUCTURADA
Lenguaje de Programación
CARACTERÍSTICAS
3/10
PROGRAMACIÓN ESTRUCTURADA
Lenguaje de Programación
MÓDULOS
Comunicación:
- Variables globales y locales
- Argumentos de llamada
4/10
PROGRAMACIÓN ESTRUCTURADA
Lenguaje de Programación
NOMBRE DE MÓDULOS
C++ Funciones
Pascal Procedimientos
Cobol Secciones
Matlab Funciones
5/10
PROGRAMACIÓN ESTRUCTURADA
Lenguaje de Programación
Función
function [s1,s2,...sn]=nombre_función(e1,e2,...em)
........
s1=e1*e2*pi/10.4;
........
........
sn=s2/cos(pi/2*e4);
........
........
return
6/10
PROGRAMACIÓN ESTRUCTURADA
Lenguaje de Programación
Programa.m romano.m
clc; function romano(d,z1,z2,z3)
clear all; if(d == 9)
n=input('Ingrese número: '); fprintf(1,'%s%s',z1,z3);
fprintf(1,'Equivalente romano = '); else
r=n; if(d > 4)
% Miles fprintf(1,'%s',z2);
digito=fix(r/1000); for j=1:d-5
r=rem(r,1000); fprintf(1,'%s',z1);
romano(digito,'M',' ',' '); end
% Centenas else
digito=fix(r/100); if(d == 4)
r=rem(r,100); fprintf(1,'%s%s',z1,z2);
romano(digito,'C','D','M'); else
% Decenas for j=1:d
digito=fix(r/10); fprintf(1,'%s',z1);
r=rem(r,10); end
romano(digito,'X','L','C'); end
% Unidades end
digito=r; end
romano(digito,'I','V','X'); return
close all
7/10
PROGRAMACIÓN ESTRUCTURADA
Lenguaje de Programación
Programa.m seno.m
clc; function [s] = seno(a)
clear all; x=a*pi/180;
resp='s'; s=x;
while(resp == 's' || resp == 'S') for i=2:4
ang=input('Ingrese ángulo (grados) = '); n=2*i-1
[X]=seno(ang); [p]=pot(x,n);
fprintf(1,'\n Seno(%0.1f)=%0.4f',ang,X); [f]=fact(n);
resp=input('Desea ingresar otro valor [s/n]: ','s'); if(rem(i,2) == 0)
end s=s-p/f;
else
s=s+p/f;
end
pot.m fact.m end
function [p] = pot(x,n) function [f] = fact(n) return
p=1; f=1;
for i=1:n for i=1:n
p=p*x; f=f*i;
end end
return return
8/10
PROGRAMACIÓN ESTRUCTURADA
Lenguaje de Programación
9/10
PROGRAMACIÓN ESTRUCTURADA
Lenguaje de Programación
Programa.m seno.m
clc; function seno
clear all; global ang s x n p f
global ang s x=pi/180;
resp='s'; s=x;
while(resp == 's' || resp == 'S') for i=2:4
ang=input('Ingrese ángulo (grados) = '); n=2*i-1
seno pot
fprintf(1,'\n Seno(%0.1f)=%0.4f',ang,X); fact
resp=input('Desea ingresar otro valor [s/n]: ','s'); if(rem(i,2) == 0)
end s=s-p/f;
else
s=s+p/f;
end
pot.m fact.m end
return
function pot function fact
global x p global n f
p=1; f=1;
for i=1:n for i=1:n
p=p*x; f=f*i;
end end
return return
10/10
ARCHIVOS
Lenguaje de Programación
INTRODUCCIÓN
- Tamaño
- Tiempo
- Transmisión
1/7
ARCHIVOS
Lenguaje de Programación
Tipos de acceso
Secuencial Directo
Registro 1 Registro 1
Registro 2 Registro 2
Registro 3 Registro 3
P
Registro 4 Registro 4
R
Registro 5 Registro 5
O
Registro 6 G Registro 6
Registro 7 R Registro 7
Registro 8 A
Registro 8
Registro 9
M
A Registro 9
Registro 10 Registro 10
: :
: :
Registro n Registro n
2/7
ARCHIVOS
Lenguaje de Programación
OPERACIONES
3/7
ARCHIVOS
Lenguaje de Programación
Permiso:
fid=fopen(’nombre’,’permiso’) r : para leer
w : para escribir
Ejemplo
.
.
.
Ide=fopen(‘Temp.dat’,’r’);
.
.
.
Pr=fopen(‘Informe.res’,’w’);
.
.
.
4/7
ARCHIVOS
Lenguaje de Programación
Ejemplos
Variable numérica
ft=fopen(‘Temp.dat’,’r’); A= 1 2 3 4 5 6 7 8 9 10 11 12
A=fscanf(ft,’%f’)
Temp.dat
1 2 3 4 5 6 Variable numérica
7 8 9 10 ft=fopen(‘Temp.dat’,’r’); A= 1 3 5
11 12
A=fscanf(ft,’%f’,[2 3]) 2 4 6
5/7
ARCHIVOS
Lenguaje de Programación
fprintf(fid,’formato’,variables)
Ejemplo
zq=fopen(‘Informe.res’,’w’);
.
.
fprintf(zq,’Los resultados son:’)
for I=1:N
fprintf(zq,’\n %5.1f’,b(I));
end
.
.
.
6/7
ARCHIVOS
Lenguaje de Programación
fclose(fid)
Ejemplo
.
.
.
Ide=fopen(‘Temp.dat’,’r’);
.
.
.
Pr=fopen(‘Informe.res’,’w’);
.
.
.
fclose(Ide);
fclose(Pr);
7/7
MATLAB
Lenguaje de Programación
1/17
MATLAB
Lenguaje de Programación
2/17
MATLAB
Lenguaje de Programación
Load nombre.ext
Escritura manual
Editor de texto
Recupera arreglo
nombre
Archivo H=Load(‘nombre.ext’)
nombre.ext
Recupera arreglo
H
3/17
MATLAB
Lenguaje de Programación
FUNCIONES MATEMÁTICAS
4/17
MATLAB
Lenguaje de Programación
5/17
MATLAB
Lenguaje de Programación
GENERACIÓN DE ARREGLOS
6/17
MATLAB
Lenguaje de Programación
MANIPULADORES MATRICIALES
c = [a b ] c = [3 2 6 8 9 1 7 4 8 2 ]
a = [ 3 2 6 8 9]
b = [1 7 4 8 2]
c = [ a ;b ] c= [ 3 2 6 8 9
1 7 4 8 2 ]
{}
3
2
d = a' d= 6
8
9
7/17
MATLAB
Lenguaje de Programación
k = f .∗g k= [ 7 16 27
16 35 18 ]
m = h∗ f ' m = [ 31 76 ]
h = [6 2 7]
f = [ 1 2 3
4 5 6 ] n = h .∗g (1,:) n = [ 42 16 63 ]
g= [ 7 8 9
4 7 3 ]
p = [h (1 :2)]' .∗g (: , 2) p= [ ] 48
14
q = f .^ 2 q= [ 1 4 9
16 25 36 ]
8/17
MATLAB
Lenguaje de Programación
x=(0:0.1:5*pi);
y=sin(x);
plot(x,y); 1
0 .8
plot(x,y,’r’) 0 .6
0 .4
0 .2
-0 .2
-0 .4
-0 .6
-0 .8
-1
0 2 4 6 8 10 12 14 16
9/17
MATLAB
Lenguaje de Programación
x=[1 3 4 5 7 10]
y=[0 6 -3 1 4 9]
plot(x,y)
plot(x,y,'go-')
plot(x,y,'g',x,y,'bo')
10/17
MATLAB
Lenguaje de Programación
GRÁFICOS 3D
x ( 2, 2)
[x,y] = meshgrid(-2:0.25:2); mesh(x,y,z)
y ( 2, 2)
2
y 2 )
z = x.*exp(-x.^2 – y.^2);
z x e( x surf(x,y,z)
0.5
-0.5
2
1 2
0 1
0
-1 -1
-2 -2
11/17
MATLAB
Lenguaje de Programación
RAÍCES DE FUNCIONES
clc;
f(x)= x3 - 10x - 1 clear all;
for i=1:3
80
V=input('Entre valor aproximado: ');
60
x(i)=fzero('p1',V);
40
end
20
clc;
0 fprintf(1,'\n Las raíces son:\n');
-20 for i=1:3
-40
fprintf(1, '%7.3f\n',x(i));
end
-60
close
-80
-5 -4 -3 -2 -1 0 1 2 3 4 5
Resultados p1.m
Las raíces son: -3.111 function [y]=p1(x);
-0.100 y=x^3-10*x-1;
3.211 return
12/17
MATLAB
Lenguaje de Programación
MÍNIMO DE FUNCIONES
f(x)= x3 - 10x - 1
clc;
80
clear all;
60 Vi=input('Entre inicio de intervalo: ');
Vf=input('Entre final de intervalo : ');
40
x=fmin('p2',Vi,Vf);
20 y=p2(x);
0
clc;
fprintf(1,'\n Valor mínimo = %10.3f\n',y);
-20 fprintf(1,' en X = %10.3f\n',x)
-40
close
-60
-80
-5 -4 -3 -2 -1 0 1 2 3 4 5
p2.m
function [y]=p2(x);
Resultados y=x^3-10*x-1;
Valor mínimo = -13.172 return
en X = 1.826
13/17
MATLAB
Lenguaje de Programación
POLINOMIOS
3 2
p ( x) = x − 2 x − 8 x + 10 Ajuste de curvas
p = [ 1 −2 −8 10 ]
x y
0 0
{ }
Raíces de un polinomio 1 0.8415
3.4742 2 0.9093
r=roots(p) r = 1.1127 3 0.1411
−2.5869 4 -0.7568
5 -0.9589
6 -0.2794
Polinomio de raíces
p=poly(r) p = [ 1 −2 −8 10 ]
p=polyfit(x,y,g)
14/17
MATLAB
Lenguaje de Programación
ECUACIONES DIFERENCIALES
Ecuación diferencial
de segundo orden x ( x 2 1)x x 0
x1 x x 1 x
Cambio de variables
x 2 x x 2 x
Sistema de ecuaciones de
x1 (1 x 22 )x1 x 2
x 2 x1
primer orden acopladas
15/17
MATLAB
Lenguaje de Programación
ECUACIONES DIFERENCIALES
16/17
MATLAB
Lenguaje de Programación
x
1
-1
x
-2
-3
0 2 4 6 8 10 12 14 16 18 20
17/17