Está en la página 1de 8

ALGORITMOS (ENTRADA Y SALIDA)

%1

a=input('ingrese el lado uno: ');


b=input('ingrese el lado dos: ');
c=input('ingrese el lado tres: ');
p=(a+b+c)/2;
A=sqrt(p*(p-a)*(p-b)*(p-c));
fprintf('el área del triángulo es: %0.2f m ,%2.2f m y %2.2f m es: %2.2f m^2\n',a,b,c,A)

%2

theta=input('ingrese el angulo theta: ');


M=tand(theta);
fprintf('la pendiente es: %.2f\n',M)

%3

x=input('ingrese la abscisa de (x,y): ');


y=input('ingrese la ordenada de (x,y): ');
x1=input('ingrese la abcisa de (x1,y1): ');
y1=input('ingrse la ordenada de (x1,y1): ');
M=(y-y1)/(x-x1);
fprintf('la pendiente es: %.2f\n',M)

%4

r=input('ingrese el radio del circulo: ');


a=pi*r^2;
p=2*pi*r;
fprintf('el area es: %.2f y el perimetro es: %.2f\n',a,p)

%5

a=input('ingrese el ancho del rectangulo: ');


l=input('ingrese el largo del rectangulo: ');
a=a*l;
p=2*(a+l);
fprintf('el area es: %.f y el perimetro es: %.f\n',a,p)
%6

a=input('ingrese el primer lado del triangulo: ');


b=input('ingrese el segundo lado del triangulo: ');
theta=input('ingrese el angulo theta: ');
c=sqrt(a^2+b^2-2*a*b*cosd(theta));
fprintf('el tercer lado es: %.2f\n',c)

%7

a=input('primer coeficiente, a:');


b=input('segundo coeficiente, b:');
c=input('tercer coeficiente, c:');
x=sqrt(b*b-4*a*c);
m=(-b+x)/(2*a);
N=x+m;
fpritf('la suma N es: %.f\n',N)

%8

x = input('ingrese el numero de datos: ');


y = input('ingrese los datos:[a,b,...] ');
P= sum(y)/x;
fprintf('el promedio es: %.f\n',P)

%9

ang=input('ingrese el angulo en grados');


vo=input('ingrese la velocidad inicial');
x=vo*vo*sind(2*ang)/9.8;
fprintf('velocidad %2.4fm/s,angulo de tiro %i°,alcance %5.2f m\n',vo,ang,x)

% 10

h=input('ingrese la altura: ');


r=input('ingrese el radio: ');
Ab=pi*r^2;
v=Ab*h;
Al=2*pi*r*h;
fprintf('area de la base %2.4f m^2, volumen %2.2f m^3, area lateral %2.2f m^2\n',Ab,v,Al)
GRAFICAS BIDIMENCIONALES

%ejercicio 01
x=0:0.1:10;
y=sin(x).*exp(-0.4*x);
plot(x,y)
grid on
%ejercicio 02
t=0:0.01:2*pi;
x=4*cos(t)-cos(4*t);
y=4*sin(t)-sin(4*t);
hold on %varias graficas en la misma ventana
plot(t,x,'r')
plot(t,y,'g')
hold off
grid on
%ejercicio 03
a=0:0.01:2*pi;
r=sin(2*a).*cos(2*a);
plot(r,a)
grid on
%ejercicio 04
x=0:0.01:2*pi;
y1=sin(x);
y2=cos(x);
subplot(1,2,1)
plot(x,y1)
grid on
title('grafica 1')
xlabel('eje x')
ylabel('eje y')
subplot(1,2,2)
plot(x,y2)
grid on
xlabel('eje x')
ylabel('eje y')
%ejercicio 05
x=0:0.001:2*pi;
y1=sin(x);
y2=cos(x);
y3=sec(x);
y4=csc(x);
subplot(1,4,1)
plot(x,y1)
grid on
title('grafica 1')
subplot(1,4,2)
plot(x,y2)
grid on
title('grafica 2')
subplot(1,4,3)
plot(x,y3)
grid on
title('grafica 3')
subplot(1,4,4)
plot(x,y4)
grid on
title('grafica 4')

%ejercicio 06
ezplot('y =sin(x)') ezplot('y =sin(2*x)') ezplot('y =sin(3*x)')
ezplot('y =cos(x)') ezplot('y =cos(2*x)') ezplot('y =cos(3*x)')
ezplot('y =tan(x)') ezplot('y =tan(2*x)') ezplot('y =tan(3*x)')
ezplot('y =cot(x)') ezplot('y =cot(2*x)') ezplot('y =cot(3*x)')
ezplot('y =sec(x)') ezplot('y =sec(2*x)') ezplot('y =sec(3*x)')
ezplot('y =csc(x)') ezplot('y =csc(2*x)') ezplot('y =csc(3*x)')

%ejercicio 07
%seno
x=0:pi/20:10*pi;
y1=sin(x);
y2=sin(2*x);
y3=sin(3*x);
hold on
plot(x,y1,'r')
plot(x,y2,'k')
plot(x,y3,'g')
grid on
title('funcion seno')
xlabel('eje x')
ylabel('eje y')
legend('sin(x)','sin(2*x)','sin(3*x)')
%coseno
x=0:pi/20:10*pi;
y1=cos(x);
y2=cos(2*x);
y3=cos(3*x);
hold on
plot(x,y1,'r')
plot(x,y2,'k')
plot(x,y3,'g')
grid on
title('funcion coseno')
xlabel('eje x')
ylabel('eje y')
legend('cos(x)','cos(2*x)','cos(3*x)')
%tangente
x=0:pi/20:10*pi;
y1=tan(x);
y2=tan(2*x);
y3=tan(3*x);
hold on
plot(x,y1,'r')
plot(x,y2,'k')
plot(x,y3,'g')
grid on
title('funcion tangente')
xlabel('eje x')
ylabel('eje y')
legend('tan(x)','tan(2*x)','tan(3*x)')
%cotangente
x=0:pi/20:10*pi;
y1=cot(x);
y2=cot(2*x);
y3=cot(3*x);
hold on
plot(x,y1,'r')
plot(x,y2,'k')
plot(x,y3,'g')
grid on
title('funcion cotangente')
xlabel('eje x')
ylabel('eje y')
legend('cot(x)','cot(2*x)','cot(3*x)')
%secante
x=0:pi/20:10*pi;
y1=sec(x);
y2=sec(2*x);
y3=sec(3*x);
hold on
plot(x,y1,'r')
plot(x,y2,'k')
plot(x,y3,'g')
grid on
title('funcion secante')
xlabel('eje x')
ylabel('eje y')
legend('sec(x)','sec(2*x)','sec(3*x)')
%cosecante
x=0:pi/20:10*pi;
y1=csc(x);
y2=csc(2*x);
y3=csc(3*x);
hold on
plot(x,y1,'r')
plot(x,y2,'k')
plot(x,y3,'g')
grid on
title('funcion cosecante')
xlabel('eje x')
ylabel('eje y')
legend('csc(x)','csc(2*x)','csc(3*x)')

%ejercicio 09
%9.1
x=-4:0.1:4;
y=x.*exp(-x.^2);
plot(x,y)
grid on
%9.2
x=0:0.1:5;
y=x.*exp(-x.^2);
plot(x,y)
grid on
%9.3
x=-10:0.1:10;
y=x.*exp(-x.^2);
plot(x,y)
grid on
%ejercicio 10
ezplot('x*(x^2+4)^2') % a)
grid on
ezplot('x*(x-sqrt(x)') % b)
grid on

ezplot('log10(x)/x') % c)
grid on
ezplot('x*(x-2)/(x+1)*(x-2)') % d)
grid on
ezplot('sin(1/x)') % e)
grid on
ezplot('x/exp(abs(x-1))') % f)
grid on
t=-pi:0.01:pi; % g)
plot(2*cos(t).^3,2*sin(t).^3)
grid on
t=-pi:0.01:pi; % h)
plot(3*cos(t),2*sin(2*t))
grid on
t=-pi:0.01:pi; % i)
plot(3*cos(cos(t)+1)/2,2*sin(2*t))
grid on
t=-3:0.01:3; % j)
plot((t/pi).*(12*(t/pi).^2-9),(((t/pi).^2+2)*16(t/pi).^2+))
grid on
t=-pi:0.01:pi; % k)
plot(sin(2*t)+sin(t),-cos(2*t)-cos(t))
grid on
t=-pi:0.01:pi; % l)
plot(exp(t/4).*sin(2*t),exp(t/4).*cos(2*t))
grid on
t=-3*pi:0.01:3*pi; % m)
plot(t-11*sin(3*t)/10,-22*cos(3*t)/10)
grid on

%ejercicio 12
x=-2:0.01:4;
y=(x<0).*(x.^2)+((x>=0)&(x<1)).*1+(x>=1).*(-x+2);
plot(x,y,'g')
grid on

%ejercicio 13
x=-10:0.01:10;
y=((x>=-3)&(x<0)).*3+((x>0)&(x<3)).*(x+3)+((x>=3)&(x<6)).*(-2*x+12);
plot(x,y,'r')
grid on

%ejercicio 14
x=-20:0.01:25;
y=((x>=-4)&(x<0)).*(x+4)+((x>=0)&(x<8)).*4+(x>=12).*(x-12);
plot(x,y,'k')
grid on

%ejercicio 15
x=-pi:pi/80:pi; % a)
y=7-7*sin(x);
polar(x,y,'r')
x=-pi:pi/80:pi; % b)
y=3-6*sin(x);
polar(x,y,'y')
x=-pi:pi/80:pi; % c)
y=sin(6*x);
polar(x,y,'k')
x=-pi:pi/80:pi; % d)
y=cos(8*x);
polar(x,y,'g')
x=-pi:pi/80:pi; % e)
y=sqrt(5*cos(2*x));
polar(x,y,'b')

También podría gustarte