visual matlab 20

22
UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN, TACNA Facultad de Ingenierías Escuela Académico Profesional de Ingeniería Geológica - Geotecnia PRACTICA DE PROGRAMACION Y VISUALIZACION EN MATLAB Asignatura: COMPUTACION E INFORMATICA Apellidos: CHAMBI TICAHUANCA Nombres: CESAR Nº de Matrícula: 08 - 32810

Upload: cesar-cr

Post on 10-Mar-2015

64 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Visual Matlab 20

UNIVERSIDAD NACIONAL JORGE BASADRE GROHMANN, TACNAFacultad de Ingenierías

Escuela Académico Profesional de Ingeniería Geológica - Geotecnia

PRACTICA DE PROGRAMACION Y VISUALIZACION EN MATLAB

Asignatura: COMPUTACION E INFORMATICA

2009

Apellidos: CHAMBI TICAHUANCANombres: CESARNº de Matrícula: 08 - 32810

Page 2: Visual Matlab 20

PRACTICA DE PROGRAMACIÓN Y VISUALIZACIÓN EN MATLAB

1. Desarrolle un algoritmo que permita leer un valor para el radio(r), calcular el área (A) de un circulo A=πr2 y escribir su valor.function pushbutton1_Callback(hObject, eventdata, handles)r=str2double(get(handles.edit1,'string'));A=pi*(r*r);set(handles.edit2,'string',A) function pushbutton2_Callback(hObject, eventdata, handles)close()

Page 3: Visual Matlab 20

2. Determinar la hipotenusa de un triangulo rectángulo conocidos las longitudes de sus catetos.function pushbutton1_Callback(hObject, eventdata, handles)A=str2double(get(handles.edit1,'string'));B=str2double(get(handles.edit2,'string'));C=sqrt((A*A)+(B*B));set(handles.edit3,'string',C) function pushbutton2_Callback(hObject, eventdata, handles)close()

3. Desarrolle un algoritmo que permita leer un valor cualquiera N y escribir si dicho número es par o impar.function pushbutton1_Callback(hObject, eventdata, handles)N=str2double(get(handles.edit1,'string'));if rem(N,2)==0 P='es par';else P='es impar';endset(handles.edit2,'string',P)function pushbutton2_Callback(hObject, eventdata, handles)close()

Page 4: Visual Matlab 20

4. Desarrolle un algoritmo que permita leer un valor cualquiera N y escribir en la pantalla si dicho número es positivo o negativo.function pushbutton1_Callback(hObject, eventdata, handles)A=str2double(get(handles.edit1,'string'));if A>0 N='es positivo';else if A==0; N='es neutro'; else N='es negativo'; endendset(handles.edit2,'string',N) function pushbutton2_Callback(hObject, eventdata, handles)close()

Page 5: Visual Matlab 20

5. Desarrolle un algoritmo que permita leer un valor cualquiera A y escribir si dicho número es múltiplo de B.

function pushbutton1_Callback(hObject, eventdata, handles)N=str2double(get(handles.edit1,'string'));Z=str2double(get(handles.edit2,'string'));if rem(N,Z)==0

P=('"N" es multiplo de "Z"');else

P=('"N no es multiplo de "Z"');endset(handles.edit3,'string',P)function pushbutton2_Callback(hObject, eventdata, handles)close()

6. Desarrolle un algoritmo que le permita leer un valor entero cualquiera A y escribir si dicho número es común divisor de otros dos valores leídos B y C.function pushbutton1_Callback(hObject, eventdata, handles)A=str2double(get(handles.edit1,'string'));B=str2double(get(handles.edit2,'string'));C=str2double(get(handles.edit3,'string'));if B>A P=rem(B,A); if P==0 if C>A Q=rem(C,A); if Q==0 P=('"A" es comun divisor de "B" y "C"'); else P=('"A" no es comun divisor de "B" y "C"'); end else P=('"A" no es comun divisor de "B" y "C"'); end else P=('"A" no es comun divisor de "B" y "C"'); endelse

Page 6: Visual Matlab 20

P=('"A" no es comun divisor de "B" y "C"');endset(handles.edit4,'string',P) function pushbutton2_Callback(hObject, eventdata, handles)close()

7. Desarrolle un algoritmo que permita leer un valor entero cualquiera A y escribir si dicho número es común múltiplo de B y C. B y C también se deben leer desde el teclado.function pushbutton1_Callback(hObject, eventdata, handles)A=str2double(get(handles.edit1,'string'));B=str2double(get(handles.edit2,'string'));C=str2double(get(handles.edit3,'string'));if A>=B P=rem(A,B); if P==0 if A>=C Q=rem(A,C); if Q==0 P=('"A" es comun multiplo de "B" y "C"'); else P=('"A" no es comun multiplo de "B" y "C"'); end else P=('"A" no es comun multiplo de "B" y "C"'); end else P=('"A" no es comun multiplo de "B" y "C"'); endelse P=('"A" no es comun multiplo de "B" y "C"');endset(handles.edit4,'string',P) function pushbutton2_Callback(hObject, eventdata, handles)close()

Page 7: Visual Matlab 20

8. Desarrolle un algoritmo para hallar las raíces de la ecuación cuadrática ax2+bx+c= 0.function pushbutton1_Callback(hObject, eventdata, handles)a=str2double(get(handles.edit1,'string'));b=str2double(get(handles.edit2,'string'));c=str2double(get(handles.edit3,'string'));if a~=0 d=(b*b)-(4*a*c); if d>0 x1=(-b+sqrt(d))/(2*a); x2=(-b-sqrt(d))/(2*a); set(handles.edit4,'string',x1); set(handles.edit5,'string',x2); else if d==0 x1=-b/(2*a); x2=x1; set(handles.edit4,'string',x1); set(handles.edit5,'string',x2);disp(x2); else x1=('tiene raices complejas'); x2=x1; set(handles.edit4,'string',x1); set(handles.edit5,'string',x2); end endelse x=-c/b; set(handles.edit6,'string',x);end function pushbutton2_Callback(hObject, eventdata, handles)close()

Page 8: Visual Matlab 20

9. Desarrolle un algoritmo que le permita realizar la suma a los N primeros números naturales: 1, 3, 5, 7…function pushbutton1_Callback(hObject, eventdata, handles)N=str2double(get(handles.edit1,'string'));S=0;for i=1:N S=S+(2*i)-1;endset(handles.edit2,'string',S) function pushbutton2_Callback(hObject, eventdata, handles)close()

Page 9: Visual Matlab 20

10. Desarrolle un algoritmo que calcule el promedio de los primeros números naturales.function pushbutton1_Callback(hObject, eventdata, handles)N=str2double(get(handles.edit1,'string'));S=0;for i=1:N S=S+i;endP=S/N;set(handles.edit2,'string',P) function pushbutton2_Callback(hObject, eventdata, handles)close()

11. Desarrolle un algoritmo que le permita sacar y escribir el cuadrado de cada uno de ellos.function pushbutton1_Callback(hObject, eventdata, handles)N=str2double(get(handles.edit1,'string'));esge='';for i=1:N Q=i*i; esge1=sprintf('el cuadrado de %d es: %g \n',i,Q); esge=[esge,esge1];endset(handles.edit4,'string',esge); function pushbutton2_Callback(hObject, eventdata, handles)close()

Page 10: Visual Matlab 20

12. Desarrolle un algoritmo que le permita leer un valor entero positivo N y calcule su factorial.function pushbutton1_Callback(hObject, eventdata, handles)N=str2double(get(handles.edit1,'string'));FAC=1;for i=1:N,1; FAC=FAC*i;endset(handles.edit2,'string',FAC) function pushbutton2_Callback(hObject, eventdata, handles)close()

Page 11: Visual Matlab 20

13. Desarrolle un algoritmo que le permita leer un valor entero positivo N y decir si es primo o no.function pushbutton1_Callback(hObject, eventdata, handles)N=str2double(get(handles.edit1,'string'));if N>=0 if N>3 Q=rem(N,2); if Q>=1 R=rem(N,3); if R>=1 P=('es numero primo'); else P=('no es numero primo'); end else P=('no es numero primo'); end else P=('es numero primo'); endendset(handles.edit2,'string',P) function pushbutton2_Callback(hObject, eventdata, handles)close()

14. Desarrolle un algoritmo que permita realizar la escritura de los primeros N números naturales.function pushbutton1_Callback(hObject, eventdata, handles)K=str2double(get(handles.edit1,'string'));esge='';for N=2:K J=2; while J<=N if rem(N,J)==0 if J~=N J=N+1;

Page 12: Visual Matlab 20

else J=J+1; esge1=sprintf('El Numero %d es primo \n',N); esge=[esge,esge1]; end else J=J+1; end endendset(handles.edit3,'string',esge)function pushbutton2_Callback(hObject, eventdata, handles)close()

15. Desarrolle un algoritmo que le permita leer N valores y calcular la media aritmética.function pushbutton1_Callback(hObject, eventdata, handles)X=str2num(get(handles.edit1,'string'));N=length(X);S=0;for I=1:N S=S+X(I);endM=S/N;set(handles.edit3,'string',M) function pushbutton2_Callback(hObject, eventdata, handles)close()

Page 13: Visual Matlab 20

16. Desarrolle un algoritmo que le permita leer N valores, sumar todos los valores y decir cuál es el mayor, cual es el menor y cuál es la suma.function pushbutton1_Callback(hObject, eventdata, handles)x=str2num(get(handles.edit1,'string'));n=length(x);s=x(1);i=1;men=x(1);may=x(1);while i<=n-1 if may<x(i+1) may=x(i+1); end if men>x(i+1) men=x(i+1); end s=s+x(i+1); i=i+1;endset(handles.edit2,'string',s);set(handles.edit3,'string',may);set(handles.edit4,'string',men); function pushbutton2_Callback(hObject, eventdata, handles)close()

Page 14: Visual Matlab 20

17. Desarrolle un algoritmo que le permita leer N valores y escribir independientemente el

promedio de pares e impares.function pushbutton1_Callback(hObject, eventdata, handles)x=str2num(get(handles.edit1,'string'));N=length(x);P=0;L=0;K=0;J=0;for I=1:N if rem(x(I),2)==0 P=P+x(I); K=K+1; else L=L+x(I); J=J+1; endendPar=P/K;Impar=L/J;set(handles.edit3,'string',Par)set(handles.edit4,'string',Impar) function pushbutton2_Callback(hObject, eventdata, handles)close()

Page 15: Visual Matlab 20

18. Desarrolle un algoritmo que le permita sumar los N primeros términos de la sucesión

1, 1/2, 1/222!, 1/233!, 1/244!...function pushbutton1_Callback(hObject, eventdata, handles)N=str2double(get(handles.edit1,'string'));F=1;P=1;S=1;for I=1:N-1 F=F*I; P=P*2; S=S+1/(P*F);endset(handles.edit2,'string',S) function pushbutton2_Callback(hObject, eventdata, handles)close()

Page 16: Visual Matlab 20

19. Desarrolle un algoritmo que le permita sumar los N primeros términos de la ucesión: 1, x, x2/2!, x3/3!, x4/4!...function pushbutton1_Callback(hObject, eventdata, handles)X=str2double(get(handles.edit1,'string'));N=str2double(get(handles.edit2,'string'));M=1;FAC=1;S=1;P=N-1;for i=1:P M=M*X; FAC=FAC*i; S=S+(M/FAC);endset(handles.edit3,'string',S) function pushbutton2_Callback(hObject, eventdata, handles)close()

Page 17: Visual Matlab 20

20. Desarrolle un algoritmo que le permita sumar los N primeros términos de la sucesión: x, -x3/3!, x5/5!, -x7/7!...function pushbutton1_Callback(hObject, eventdata, handles)X=str2double(get(handles.edit1,'string'));N=str2double(get(handles.edit2,'string'));M=1;FAC=1;S=1;P=N-1;for i=1:P M=M*X; FAC=FAC*i; S=S+(M/FAC);endset(handles.edit3,'string',S) function pushbutton2_Callback(hObject, eventdata, handles)close()