Documentos de Académico
Documentos de Profesional
Documentos de Cultura
If condición
Bloque de sentencias1
Else
Bloque de sentencias2
End
Ejemplo:
x=3;
if (rem(x,2)==0)
fprintf('El numero es par ');
else
fprintf('El numero es impar ')
end
if
CONDICIONES MULTIPLES
elseif Condición v
If condición1 1
Bloque de sentencias1
Bloque de
Elseif condición2 elseif Condición v sentencias 1
2
Bloque de sentencias2
Elseif condición3 Condición v Bloque de
3 sentencias 2
Bloque de sentencias3
Bloque de
End sentencias 3
OPERADORES
2 == 2 ESTABLECE LA CONDICION DE IGUALDAD
Respuesta 1 que significa True o Verdadero
eq 2 2
Respuesta 1
and(1==1,2==2) and se debe cumplir las dos proposiciones para que sea verdad
Respuesta 1
O también
1==1 & 2==2 and o & son iguales “Y”
Ejemplo: 1 1
>> for i =1:1:2
for j = 1:1:7 1 2
if j>2i 2 1
break
2 2
else
disp(i,j) 2 3
end 2 4
end
end
FUNCIONES
BLOQUE DE INSTRUCCIONES QUE CUMPLE UNA TAREA ESPECIFICA
function [y]=fcubico(x)
y=2*x^3+8;
1 0 0 0
0 2 0 0
0 0 3 0
0 0 0 4
Funcion
function maltina(n)
A=zeros(n);
j=1;
for i=1:n La matriz de orden 4
k=1; es:
while k <=1 A=
A(i,j)=j;
j=j+1; 1 0 0 0
k=k+1; 0 2 0 0
end 0 0 3 0
end
0 0 0 4
Fprintf(‘La matriz de orden
%3.0f \n es: ‘, n);
A
end
Elaborar un programa que
halle la siguiente matriz.
Ejm. Para la matriz de orden
4 el programa debe
visualizar lo siguiente:
1 0 0 0
2 3 0 0
4 5 6 0
7 8 9 10
Funcion Matriz latina
function [A]=matriz(n)
a=1;
for i=1:n
for j=1:n [y]=matriz(4)
if i>=j
y=
A(i,j)=a;
a=a+1; 1 0 0 0
else 2 3 0 0
A(i,j)=0; 4 5 6 0
end 7 8 9 10
end
End
>> [A]=matriz(4)
clc
a=input('Ingrese el Primer Lado del triangulo: ');
b=input('Ingrese el Segundo Lado del triangulo: ');
c=input('Ingrese el Tercer Lado del triangulo: ');
if (a+b>c) & (b+c>a) & (c+a>b)
disp('El triangulo existe ');
if a==b & a==c
disp('Es triangulo equilatero');
end
if (a==b & a~=c) | (c==b & b~=a) | (a==c & a~=b)
disp ('Es triangulo isóceles ');
end
if a~=b & a~=c & b~=c
disp('Es Triangulo Escaleno ');
end
else
disp('el Triangulo no existe');
End
%Funcion que calcula Perimetro y area
%Funcion que calcula Perimetro y area
function [PERIMETRO, AREA]=mitriangulo1(a, b, c)
PERIMETRO=perimetro(a, b, c);
AREA=area(a, b, c);
clc
function p=perimetro(x, y, z)
p=(x+y+z);
fprintf('Perimetro : %4.2f', p);
function s=area(x, y, z)
p1=(x+y+z)/2;
s=sqrt(p1*(p1-x)*(p1-y)*(p1-z))
fprintf('Area : %4.2f', s)
function y=fun(x)
if x<=0
y=0;
else if x(x>0) & (x<1)
y=x+log(x)+1;
else
y=x ^ (log(x));
end