Está en la página 1de 22

Programa con for:

1.-
disp('-----------------------------------------------------------------------------------')
disp ('programa para determinar el tiempo de alcance de 2 móviles')
disp('-----------------------------------------------------------------------------------')

clc
clear all
va=input('velocidad del móvil a lento=');
vb=input('velocidad del móvil b rápido=');
d=input('distancia de separación entre móviles=');
da=0;
db=d;
te=d/(vb-va);
if da~=db;
disp [tiempo distanciaA distanciaB]
for t=0:te;
da=d+va*t;
db=vb*t;
disp([t da db])
end
end

2.-
disp('----------------')
disp('integracion')
disp('----------------')
clc
clear all
a=input('limite inferior=');
b=input('limite superior=');
n=input('numero de variables=');
h=(b-a)/n;
n=n+1;
y=zeros(n,1);
x=zeros(n,1);
suma=0;
for i=1:n
x(i)=a+h*(i-1);
y(i)=feval(x,i);
end
for i=2:n-1
if rem(i-1,3)==0
suma=suma+2*y(i);
else
suma=suma+3*y(i);
end
end
p=3*h*(y(i)+suma+y(n))/8;
%integracion
a=input('limite inferior');
b=input('limite superior');
n=input('numero de variables');
h=(b-a)/n;
n=n+1;
y=zeros(n,1);
x=zeros(n,1);
suma=0;
for i=1:n
x(i)=a+h*(i-1);
y(i)=feval(x(i));
end
for i=2:n-1
if rem(i-1,3)==0
suma=suma+2*y(i);
else
suma=suma+3*y(i);
end
end
p=3*h*(y(i)+suma+y(n))/8;
simpsom8('exp2',0,1,9);

3.-
disp('-----------------------------------------------')
disp('para hallar el numero de divisores')
disp('-----------------------------------------------')

clc
clear all
n=input('ingrese valor=')
c=0;
for g=(1:n);
if mod(n,g)==0
d=n;
c=c+1;
end
end
'el numero de divisores es'
disp([c])
4.-
disp('--------------------------------------------------')
disp('para saber si es un numero perfecto')
disp('-------------------------------------------------')

clc
clear all
n=input('ingrese el numero=')
while n<=0;
n=input('ingrese el numero=')
end
c=0;
for d=1:n;
resto=rem(n,d);
if resto==0
c=c+1;
end
end
disp(c)

5.-
disp('----------------------------')
disp('suma de cuadrados')
disp('----------------------------')

clc
clear all
disp [numero suma]
for n= 7:49;
if n>8;
S=n*(n+1)*(2*n+1)/6;
disp([n,S])
end
end

6.-
disp('-----------------------------------------------')
disp('para hacer una tabla de multiplicar')
disp('-----------------------------------------------')

clc
clear all
m=2;
disp [numero suma]

for a=0:1:12;
if a~=2
f=m*a;
disp([a,m,f])
end
end
7.-
disp('----------------------------------------')
disp('tabla de multiplicar mas algo')
disp('----------------------------------------')

clc
clear all
m=input('ingrese valor a m=');
h=input('ingrese valor a h=');
p=input('ingrese valor a p=');
for c=0:1:p;
if c>0;
D=m*c+h;
disp([m,h,c,D])
end
end
8.-
disp('------------------------------------------')
disp('para hallar la velocidad angular')
disp('------------------------------------------')

clc
clear all
d=input('ingrese el valor del desplazamiento:');
t=input('ingrese el tiempo:');
if t>0
end
for D=1:d;
w=(D.*pi./180)./t;
disp([D w])
end
D=1:d;
w=(D.*pi./180)./t;
plot(D,w)
title('velocidad angular')
xlabel('desplazamiento')
ylabel('velocidad')

9.-
%programa con for 3
%APLICADO AL CURSO DE FISICA i
%Programa para hallar el movimiento armónico simple de un móvil
%hallando periodo y frecuencia,posición, vel angular,
%velocidad y aceleración
clc
disp('*******************************************************************
*******')
disp('!!!!!!!!!!!!!!!!hallando periodo,
frecuencia,posición!!!!!!!!!!!!!!!!!!!!!')
disp('!!!!!!!!!!!!!!!!!velangular,velocidad y
aceleración !!!!!!!!!!!!!!!!!!!!!!')
disp('!!!!!!!!!!!!!!El movimiento armónico simple de un
móvil!!!!!!!!!!!!!!!!!!!')
disp('*******************************************************************
*******')
fprintf('\n')
t=input('ingrese el tiempo del móvil en s:');
alfa=input('ingrese el ángulo alfa en rad:');
A=input('ingrese la amplitud en m:');
m=input('ingrese la masa del movil en kg:');
K=input('ingrese la rigidez en m/s:');
format bank
disp('===================================================================
========')
disp('"""""""""""""""""""""""""""tenemos la
frecuencia"""""""""""""""""""""""""""')
disp('la frecuencia hallada es:');
disp('==tiempo frecuencia==');
for t=0:2:10;
f=1/t;
disp([num2str(t) 's ' num2str(f) 'hertz'])
end
disp('===================================================================
========')
disp('""""""""""""""""""""""""""""tenemos la
velangular""""""""""""""""""""""""""')
disp('alfa ángulo velangular :');
for t=5:1:10;
velangular=alfa/t;
disp([num2str(alfa) 'rad / ' num2str(t) 's = ' num2str(velangular)
'rad/s'])
end
disp('===================================================================
========')
disp('""""""""tenemos la posición del móvil en cualquier instante de
tiempo""""""')
disp('==tiempo posición==');
for A=0:10;
X=A*sin(velangular*t+alfa); % x=deformación
disp([num2str(t) 's ' num2str(X) 'm'])
end
disp('===================================================================
========')
disp('"""""""""""tenemos la velocidad del móvil en m/s2 para el
M.A.S""""""""""""')
disp('==amplitud velocidad==');
for A=0:2:10;
v=A*velangular*cos(velangular*t+alfa);
disp([num2str(A) 'm ' num2str(v) 'm/s2'])
end
disp('"==================================================================
========')
disp('""""""""""""""""""tenemos la aceleracion del móvil en
m/s""""""""""""""""""')
disp('==tiempo aceleración==');
for t=0:1:7;
abs(-A);
a=-A*(velangular)^2*sin(velangular*t+alfa);
disp([num2str(t) 's ' num2str(a) 'm/s'])
end
fprintf('\n')
disp(':::::::::::::::::fin de programa::::::::::::::::::')
disp('**************************************************

10.- °
clc
clear memory
clf
disp('===================================================')
disp(' CENTRO DE MASA DE "n" PARTICULAS ')
disp('===================================================')
n=input('Número de partículas: ');
mt=0;
mx=0;
my=0;
for i=1:n
fprintf(1,'Partícula: %d\n',i);
x(i)=input ('x en cm: ');
y(i)=input ('y en cm: ');
m(i)=input ('M en g: ');
while m<=0
m(i)=input ('M en g: ')
end
mt=mt+m(i);
mx=mx+x(i)*m(i);
my=my+y(i)*m(i);
end
xcm= mx/mt;
ycm= my/mt;
disp(' ')
disp('^==================================================================
==============================^')

fprintf('Particulas :%d\t');fprintf(' %10s\t','');


fprintf('Eje x :%d\t');fprintf(' %10s\t','');
fprintf('Eje y :%d\t');fprintf(' %10s\t','');
fprintf(' Masas :%d\t');fprintf('\n\n');
disp('^==================================================================
===============================^')
for k=1:n
fprintf('Particula :%d\t',k);
fprintf(' %10s\t','');
fprintf('X%d\t',k);
fprintf(':%d\t',x(k));
fprintf(' %10s\t','');
fprintf('Y%d\t',k);
fprintf(':%d\t',y(k));
fprintf(' %10s\t','');
fprintf('Masa%d\t',k);
fprintf(':%d\n',m(k));
end
fprintf('\n\n')
fprintf('EL CENTRO DE MASA ES: %d\t');
fprintf('(%d\t');
fprintf('cm %5.2f\t',xcm);fprintf(';%d\t');
fprintf('cm %5.2f\t',ycm);fprintf(';%d\t');
plot(xcm,ycm,'g+');
text(xcm,ycm,'Centro de Masa');
xlabel('Eje X'),ylabel('Eje Y'),;
hold on
for j = 1:n
plot(x(j),y(j),'rx');
text (x(j),y(j),num2str(m(j)));
end
title('CENTRO DE MASA')
grid on
hold off
Programa con if:
1.-
%Programa para hallar las diferentes series en el espectro de emisión
%del hidrogeno atómico.
%Autor:Socualaya Montoya Christian Gabriel
clc,clear all
for z=1:6
x=input('Ingrese el número de capa a donde salta el electrón(nf)del 1 al
4:');
if x>0 | x<5;
if x==1;
disp('Representa a la serie de Lyman')
disp('Pertenece a la región del espectro ultravioleta')

disp('=================================================================')
else
if x==2;
disp('Representa a la serie de Balmer')
disp('Pertenece a la región del espectro visible y ultravioleta')

disp('=================================================================')
else
if x==3;
disp('Representa a la serie de Paschen')
disp('Pertenece a la región del espectro infrarrojo')

disp('=================================================================')
else
if x==4;
disp('Representa a la serie de Brackett')
disp('Pertenece a la región del espectro infrarrojo')

disp('=================================================================')
else
disp('No presenta serie definida')
end
end
end
end
end
end

2.-

%Programa para calcular el trabajo realizado por la fuerza F=3*x^2+2*x-5


N
%entre x=2m y x=5m.
%Sabiendo que la velocidad del bloque en el punto x=2m es de 5 m/s,
calcular
%la velocidad del bloque en el punto x=5m.
%Autor: Socualaya Montoya Christian Gabriel
clc,clear
xi=input('ingrese la distancia inicial en m:');
xf=input('ingrese la distancia final en m :');
disp('=================================================')
disp('============CALCULANDO EL TRABAJO================')
for D=xi:xf
disp('Distancia(D) Fuerza(F) Trabajo(W)')
F=3*D^2+2*D-5; %Fuerza en Newton(N)
W=F*D; %Trabajo en Joules(J)
disp([num2str(D) ' m * ' num2str(F) ' N = '
num2str(W) ' J '])
end
disp('=================================================')
disp('=====CALCULANDO LA INTEGRAL DE LA FUERZA(F)======')
syms x;
f=input('ingrese la integral 3*x^2+2*x-5:');
I=inline(char(f)); %El comando inline crea una cadena y el comando char
convierte la función f en expresión simbólica
a=input('ingrese el límite inferior de la integral:');
b=input('ingrese el límite superior de la integral:');
I=int(f,a,b); %Calcula la integral de la función
disp('El valor de la integral es:')
disp(I)
disp('=================================================')
disp('=======CALCULANDO LA Vf DEL BLOQUE===============')
m=10; %Masa en Kg
Vi=5; %Velocidad inicial en m/s
I=123;
Vf=sqrt(((I+(1/2)*m*Vi^2)*2)/m);
format short
fprintf('El valor de la Vf es %g m/s.',Vf);
end
end
end
3.-
%programa con input y disp 1
%programa para hallar la cantidad de carbono en el acero(fe + c)
%tambien para hallar la densidad de la aleación
%veamos:
clc
disp('===================================================================
==================')
disp('""""""""""""""""""""" programa para hallar la densidad en esta
aleación """""""""""""')
disp('"""""""""""""""" e ingresar la cantidad de carbono en el acero para
que nos """""""""')
disp('"""""""""""""""""""""""""""" muestre en que estado esta
""""""""""""""""""""""""""""')
disp('===================================================================
==================')
masa=input('ingrese la masa del (fe + c) en kg:');
volumen=input('ingrese el volumen del acero en m3:');
dens=(masa/volumen);
fprintf('\n')
disp('*************hallando la densidad del acero******************')
disp('la densidad es:')
disp([num2str(masa) ' / ' num2str(volumen) ' = ' num2str(dens) 'kg/m3']);
fprintf('\n')
disp('===================================================================
==================')
disp('ingresamos un numero C (cant. de carbono) en kg para saber en qué
estado se encuentra')
disp('===================================================================
==================')
C=input('ingrese la cantidad de carbono en (kg) para conocer su
estado:');
if C==0
disp('=>no es acero por no contener carbono en su composición')
else
if C<0.03 %de su composición
disp('=>el acero es normal, sólido');
else
if C>2.14 %de su composición
disp('=>la composición hace que se produzca una fundición sea liquido');
else
end
end
end
fprintf('\n\n')
disp('******************fin // gracias******************')
disp('**************************************************')

4.-
%programa con if 2
%programa aplicado al curso de QUIMICA
%programa de la tabla periódica ordenados según su ORIGEN
%Se clasifican en tres
clc
disp('"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""')
disp('!!!!!!! programa para saber en qué ubicación se encuentra el
elemento!!!!!!!!')
disp('!!!!!!!!!!!!!!!! elementos clasificados, según su
origen!!!!!!!!!!!!!!!!!!!!!')
disp('!!!!!!!!!!!!!!!!! ya sea natural, artificial u
anfótero!!!!!!!!!!!!!!!!!!!!!!')
disp('"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""""""""""')
fprintf('\n')
Z=input('ingrese el peso atómico de un elemento:');
if Z>=1 && Z<=92;
disp('=>según su origen el elemento es NATURAL');
else
if Z==43;
disp('=>es el elemento tecnesio que es un ANFÓTERO');
else
if Z==61;
disp('=>es el elemento prometio que es un ANFÓTERO');
else
if Z>92 && Z<=121; %estos elementos se denominan transuránicos
disp('=>según su origen el elemento es ARTIFICIAL');
else
if Z>121;
disp('=>no se clasifica; no existe este elemento de peso atómico');
end
end
end
end
end
fprintf('\n')
disp('================================FIN //
GRACIAS================================')
disp('===================================================================
===========')
5.-
disp('----------------------')
disp('hallar numeros inpares')
disp('----------------------')
clc
clear all
a = 15
b = 10
if a > b then
disp([invertimos])
x=a
a=b
b=x
end
if a mod 2 = 0 then
a=a+1
for n = a to b
disp([n])
end

6.-
clc;clf;
disp('|||CALCULAR Y GRAFICAR LA VARIACION DE LA ENERGIA LIBRE DE
GIBBS|||')
disp('|||||||||||||||||||||DE LA SIGUIENTE
REACCION|||||||||||||||||||||')
disp('|||||||||||||||||||CH4(g)+2O2(g)=CO2(g)
+2H2O(g)|||||||||||||||||||')
disp('-------------------------------------------------')
x=input('Ingrese la entalpia del CH4 (KJ/mol) -74.8 :');
y=input('Ingrese la entalpia del CO2 (KJ/mol) -393.5 :');
z=input('Ingrese la entalpia del H2O (KJ/mol) -241.6 :');
disp('-------------------------------------------------')
m=input('Ingrese la entropía del CH4 (J/mol K) 186.3 :');
n=input('Ingrese la entropía del CO2 (J/mol K) 213.4 :');
q=input('Ingrese la entropía del H2O (J/mol K) 188.7 :');
p=input('Ingrese la entropía del 2O2 (J/mol K) 49 :');
t=input('Ingrese la temperatura (°C) 25 :');
T=t+273;%kelvin
H=y+(2*z)-x;
fprintf('LA ENTALPIA ES: %3.2f',H);disp(' (KJ/mol)');
if H>0
disp('LA REACCION ES ENDOTERMICA');
else
disp('LA REACCION ES EXOTERMICA');
end
S=(n+2*q-(m+2*p))/1000;
fprintf('LA ENTROPIA ES: %3.2f',S);disp(' (J/mol k)');
if S>0;
disp('HAY MAYOR DESORDEN');
else
disp('POCO DESORDEN');
end
G=H-T*S;
fprintf('LA ENERGIA LIBBRE DE GIBBS ES: %3.2f',G);disp('K J');
if G==0;
disp('La reacción está en equilibrio');
else
if G<0;
disp('LA REACCION ES ESPONTANEA');
else
disp('LA REACCION ES NO ESPONTANEA');
end
end
plot3(H,S,G,'r*');
title('ENERGIA LIBRE DE GIBBS')
text(H,S,G,'===> H y S da la ENERGIA LIBRE ');
xlabel('ENTALPIA (KJ/mol)');ylabel('ENTROPIA (J/mol k )');
zlabel('ENERGIA LIBRE DE GIBBS (KJ)');
grid on ;hold on;
disp('******************FIN DEL PROGRAMA *************************');

7.-
%Este programa está hecho para determinar la ubicación de un
punto
%en el plano tridimensional.
disp('=======================================================
=====');
disp('=====PROGRAMA PARA DETERMINAR LA UBICACIÓN DE UN
PUNTO======');
disp('==================EN EL PLANO
TRIDIMENSIONAL====================');
disp('=======================================================
=====');
x=input('PUNTO EN EL EJE X = ');
y=input('PUNTO EN EL EJE Y = ');
z=input('PUNTO EN EL EJE Z = ');
disp('=======================================')
if x>0 & y>0 &z>0
disp('LA COORDENADA X ES POSITIVO,')
disp('LA COORDENADA Y ES POSITIVO')
disp('LA COORDENADA Z ES POSITIVO')
disp('Y PERTENECEN AL PRIMER CUADRANTE SUPERIOR')
end
if x<0 & y>0 & z>0
disp('LA COORDENADA X ES NEGATIVO,')
disp('LA COORDENADA Y ES POSITIVO')
disp('LA COORDENADA Z ES POSITIVO')
disp('Y PERTENECEN AL SEGUNDO CUADRANTE SUPERIOR')
end
if x<0 & y<0 & z>0
disp('LA COORDENADA X ES NEGATIVO,')
disp('LA COORDENADA Y ES NEGATIVO')
disp('LA COORDENADA Z ES POSITIVO')
disp('Y PERTENECEN AL TERCER CUADRANTE SUPERIOR')
end
if x>0 & y<0 & z>0
disp('LA COORDENADA X ES POSITIVO,')
disp('LA COORDENADA Y ES NEGATIVO')
disp('LA COORDENADA Z ES POSITIVO')
disp('Y PERTENECEN AL CUARTO CUADRANTE SUPERIOR')
end
if x>0 & y>0 &z<0
disp('LA COORDENADA X ES POSITIVO,')
disp('LA COORDENADA Y ES POSITIVO')
disp('LA COORDENADA Z ES NEGATIVO')
disp('Y PERTENECEN AL PRIMER CUADRANTE INFERIOR')
end
if x<0 & y>0 & z<0
disp('LA COORDENADA X ES NEGATIVO,')
disp('LA COORDENADA Y ES POSITIVO')
disp('LA COORDENADA Z ES NEGATIVO')
disp('Y PERTENECEN AL SEGUNDO CUADRANTE INFERIOR')
end
if x<0 & y<0 & z<0
disp('LA COORDENADA X ES NEGATIVO,')
disp('LA COORDENADA Y ES NEGATIVO')
disp('LA COORDENADA Z ES NEGATIVO')
disp('Y PERTENECEN AL TERCER CUADRANTE INFERIOR')
end
if x>0 & y<0 & z<0
disp('LA COORDENADA X ES POSITIVO,')
disp('LA COORDENADA Y ES NEGATIVO')
disp('LA COORDENADA Z ES NEGATIVO')
disp('Y PERTENECEN AL CUARTO CUADRANTE INFERIOR')
end

disp('=======================================')
disp('================FIN====================')
8.-
clc
disp('=============PROGRAMA APLICADO A LA FÍSICA I=============')
disp('Un auto A se mueve a una velocidad de 59 km/h y está separado ')
disp('a una distancia de 30 km del auto B, que se mueve a una velocidad
')
disp('de 63 km/h. ¿Si el auto A llega a alcanzar a B en que tiempo lo')
disp('alcansara')
disp('INGRESO DE DATOS:')
A=input(' ingresamos la velocidad del auto A en km/h :');
B=input(' ingresamos la velocidad del auto B en km/h :');
D=input(' ingresamos la distancia D en km :');
disp('====HALLANDO EL TIEMPO DE ALCANSE PARA VER SI EL AUTO A
ALCANZA====')
disp('=====================AL AUTO B==================')
x=D/(A-B);
x=num2str(x);
x=strcat(x,' segundos');
fprintf('tiempo de alcance:%1s\t','');fprintf('%0s\t',x);
disp('=================================================')
disp('================dado al tiempo de alcance:================')
if x>0
disp('el auto A NO alcanza a B')
else
disp('el auto A alcanza a B')
end

9.-
disp('PROGRAMA QUE CALCULA LAS SOLUCIONE REALES DE UNA ECUACION DE
SEGUNDO GRADO AX^2+BX+C = 0================')
disp('===================================================================
======================================')
disp('EL PROGRAMA DEBE DEVOLVER EL NÚMERO DE SOLUCIONES DISTINTAS (UNA SI
b2-4ac=0, DOS SI b2-4ac>0 NINGUNA SI b2-4ac<0) Y CUALES SON ESAS
SOLUCIONES:================================')
disp('===================================================================
======================================')
a = input('INGRESE EL VALOR DE A= ');
b = input('INGRESE EL VALOR DE B= ');
c = input('INGRESE EL VALOR DE C= ');
disp('================================')
if (b^2)-(4*a*c)==0
x=-b/(2*a);
disp('TIENE UNA SOLUCION = ')
disp(' X ES IGUAL A :'), disp(x)
else
if (b^2)-(4*a*c)>0
x(1)=-b+sqrt((b.^2)-(4*a*c));
x(2)=-b-sqrt((b.^2)-(4*a*c));
disp('TIENE DOS SOLUCIONES = ')
disp('X1 ES IGUAL A:');
disp(x(1));
disp('X2 ES IGUAL A:')
disp(x(2))
else (b^2)-(4*a*c)<0
clc
disp('================================')
disp('NO TIENE SOLUCION')
end
end
disp('================================')

10.-
% Sirve para calcular y representar el centro de masas de un
% sistema de partículas
clear all;
clf;
clc ;clear memory
disp('
==================================================================
================')
disp(' CENTRO DE MASA DE UN SISTEMA DE
PARTICULAS ')
disp('
==================================================================
================')
n = input('Ingrese el número de partículas del sistema : ');
mt = 0;
mx = 0;
my = 0;
mz = 0;
for q=1:n
fprintf('Partícula %d\n',q);
x(q)= input ('ingrese la Coordenada x del cuerpo: ');
y(q)= input ('ingrese la Coordenada y del cuerpo: ');
z(q)= input ('ingrese la Coordenada z del cuerpo: ');
m(q)= input ('Ingrese la masa en kg del cuerpo: ');
mt = mt + m(q);
mx = mx + x(q)*m(q);
my = my + y(q)*m(q);
mz = mz + z(q)*m(q);
end
xcm = mx / mt;
ycm = my / mt;
zcm = mz / mt;
disp(' ')
disp('============================================================
====================================')

fprintf('Particulas%d\t');fprintf(' %10s\t','');
fprintf('Eje x%d\t');fprintf(' %10s\t','');
fprintf('Eje y%d\t');fprintf(' %10s\t','');
fprintf('Eje z%d\t');fprintf(' %10s\t','');
fprintf(' Masas%d\t');fprintf('\n');
disp('============================================================
=====================================')
for k=1:n
fprintf('Particula %d\t',k);
fprintf(' %10s\t','');
fprintf('X%d\t',k);
fprintf(':%d\t',x(k));
fprintf(' %10s\t','');
fprintf('Y%d\t',k);
fprintf(':%d\t',y(k));
fprintf(' %10s\t','');
fprintf('Z%d\t',k);
fprintf(':%d\t',z(k));
fprintf(' %10s\t','');
fprintf('Masa%d\t',k);
fprintf(':%d\n',m(k));
end
disp(' el cemtro de masa es :');
disp([ num2str(xcm) ' i ' num2str(ycm) ' j ' num2str(zcm) ' k ' ]
)
plot3(xcm,ycm,zcm,'rx');
text(xcm+.1,ycm+.1,zcm+.1,'Centro de Masa');
xlabel('Eje X'),ylabel('Eje Y'),zlabel('Eje Z');
hold on
for j = 1:n
plot3(x(j),y(j),z(j),'bo');
text (x(j)+.1,y(j)+.1,z(j)+.1,num2str(m(j)));
end
title('CENTRO DE MASA')
grid on
hold off

programa while:

1.- clc
clear all
disp('----------------------------------------')
disp('programa de la biseccion')
disp('----------------------------------------')
fprintf('\n');
nombre_f=input(' ingrese funcion asociada f(x)= ','s');%x.*sin(1/x)-0.2*exp(-x)
a=input(' ingrese limite inferior: ');%0.1
b=input(' ingrese limite superior: ');%0.5
fprintf('\n');
fprintf(' it a b aprox error\n');
i=1;e=1; r=0;
while e>=3E-6 & i<=10
va=r;
r=(a+b)/2;
x=a;fa=eval(nombre_f);
x=b;fb=eval(nombre_f);
x=r;fr=eval(nombre_f);
fprintf(' %3.0f %10.6f %10.6f %10.6f',i,a,b,r);
if fa*fr<=0
b=r; e=abs((r-va)/r);
fprintf(' %10.6f\n',e);
else
a=r; e=abs((r-va)/r);
fprintf(' %10.6f\n',e);
end
i=i+1;
end
fprintf('\n'); fprintf('la raiz es: %10.9f\n', r);

2.-
clc
clear all
disp('----------------------------------')
disp('programa para hallar los divisores')
disp('----------------------------------')
n=input('ingrese el numero:');
while n<=1
n=input('ingrese el numero:');
end
D=n;
sum=0;
for d=1:n;
resto=rem(D,d);
if resto==0
sum=sum+d;
disp([d])
end
end
if sum==2*d;
'perfecto'
else
' no es perfecto'
end

3.-
function m=euclides(a,b)
% Cálculo del máximo común divisor de dos números naturales
% mediante el algoritmo de Euclides
clc
clear all
disp('------------------')
disp('metodo de euclides')
disp('------------------')
a= input('ingrese el primer numero:')
b= input('ingrese el segundo numero:')
if a<b
c=b;
b=a;
a=c;
end
while b>0
c=rem(a,b);
a=b;
b=c;
end
m=a;
disp('maximo comun divisor')

4.-
clc,clear all
n=0;
while n<1;
'el numero de notas no es promediable'
n=input('cuantas notas se va a promediar:');
end
sum=0;
c=0;
nota=1;

while nota>-1 & nota<=20


while c<n
nota=input('ingrese nota:');
if nota>=0 & nota<=20
sum=sum+nota;
c=c+1;
end
end
nota=100;
end
p=sum/c;
'promedio:'
disp(p)

5.-
clear,clc
k=input('ingrese el valor del coeficiente de dilatacion lineal en (celsius)^1 :');
to=input('ingrese el valor de la temperatura inicial en grados celsius:');
tf=input('ingrese el valor de la temperatura final en grados celsius:') ;
while to>=tf
'no hay variacionde temperatura '
to=input('ingrese el valor de la temperatura inicial en grados celsius:');
tf=input('ingrese el valor de la temperatura final en grados celsius:') ;
end
disp('opcion1 dilatacion lineal');
disp('opcion2 dilatacion superficial');
disp('opcion3 dilatacion volumetrica');
x=0;
while x<=0 | x>3
x=input('ingrese el valor de x:')
end
if x==1
eleccion=1;
end
if x==2
eleccion=2;
end
if x==3
eleccion=3;
end
switch eleccion
case 1
disp('dilatacion lineal');
lo=input('ingrese el valor de la longitud inicial en m:');

vl=k*lo*(tf-to);
disp('el valor de la variacion de longitud en metros es:');
disp([vl]);

case 2
disp('dilatacion superficial');
Ao=input('ingrese el valor deL AREA inicial en m^2:');
vA=k*Ao*(tf-to);
disp('el valor de la variacion de AREA en m^2 es:');
disp([vA]);

case 3
disp('dilatacion volumetrica');
Vo=input('ingrese el valor deL VOLUMEN incial en m^3:');
vV=k*Vo*(tf-to);
disp('el valor de la variacion de VOLUMEN en m^3 es:');
disp([vV]);
end

6.-
clc,clear all
clc
clear all
disp('----------------------------------------')
disp('programa para hallar si un numero es primo')
disp('----------------------------------------')
n=input('Número natural que deseas saber si es primo ');
i=2;
primo=1;
while i<=sqrt(n)
if rem(n,i)==0 % Resto de dividir n entre i
primo=0;
break
end
i=i+1;
end
if primo
disp('El número dado es primo.')
else
disp('El número dado no es primo.')
disp('De hecho, es divisible por:')
disp(i)
end

clc,clear all
n=input('ingrese el numero:');
while n<=1
n=input('ingrese el numero:');
end
D=n;
for d=1:n;
resto=rem(D,d);
if resto==0
disp([d])
if d==2
'numero primo'
else
'divisible'
end
end
end

7.-
%programa con while 4
%Programa aplicado al curso de fisica ii
%Programa para hallar el campo eléctrico y el potencial eléctrico
%sabiendo q la constante eléctrica es k= (9*10^9) N.m^2/c^2
%calculos escalarmente
clc
disp('-------------------------------------------------------------------
---------')
disp('--PROGRAMA PARA CALCULAR EL CAMPO ELÉCTRICO(E)Y EL POTENCIAL
ELÉCTRICO(Vp)--')
disp('--------- usando la fórmula E=(9*(10^9))*Q/(d^2) y
Vp=(9*(10^9))*Q/d -------')
disp('------------------- de constante k= (9*10^9) N.m^2/c^2
---------------------')
disp('-------------------------------------------------------------------
---------')
Q=input('ingrese la carga del cuerpo en Coulomb(C): ');
d=input('ingrese la distancia en metros(m): ');
while d<0;
d=input('ingrese distancia mayor que cero: ');
end
%fórmulas
k=9*10^9;
if Q>0;
E=(9*(10^9))*Q/(d^2); %fórmula del campo
disp('hallando el campo en (N/C):');
disp(E);
Vp=(9*(10^9))*Q/d; %fórmula del potencial
disp('hallando potencial en (voltios):');
disp(Vp);
plot(E,Vp,'bo')
xlabel('campo eléctrico')
ylabel('potencial eléctrico')
title('campo eléctrico& potencial eléctrico')
hold on;
grid on;
else
if Q<0;
E1=-(9*(10^9))*Q/(d^2);
disp('hallando el campo en (N/C):');
disp(E1);
Vp1=(9*(10^9))*Q/d;
disp('hallando potencial en (voltios):');
disp(Vp1);
plot(E,Vp,'r*');
xlabel('campo eléctrico')
ylabel('potencial eléctrico ')
title('campo eléctrico& potencial eléctrico')
hold on;
grid on;
end
end
disp('"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""')
disp('_____________________________ FIN ___________________________')
disp('"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""')

8.-
clc; clf ;clear memory;format short;
disp('------------------CINETICA QUIMICA-------------------------');
disp('-PROGRAMA PARA HALLAR Y GRAFICAR LA CONSTANTE DE VELOCIDAD-');
disp('***************DEL PERMANGANATO DE POTASIO*****************');
m=input('Ingrese la masa del KMnO4 (g) 500 : ');
pm=158; %g/mol
V=input('Ingrese el volumen (L) 1 : ');
t1=input('Ingrese el tiempo en (min) 3 : ');
while t1<=1 | t1>=60 ;
disp('FUERA DEL TIEMPO EN MINUTOS');
t1=input('Ingrese el tiempo correcto');
end
t=t1*60;M=m/(pm*V);z=t+11;k=M/t;
disp(' CONSTANTE MOLARIDAD (M) TIEMPO(segundos)');
disp('RESULTADO:');
disp([num2str(k) ' = ' num2str(M) ' / ' num2str(t)]);
disp('Los 11 primeros tiempos:');
while t<=z;
t=t+1;k=M/t; %k=constante
disp([num2str(k) ' = ' num2str(M) ' / '
num2str(t)]);
grid on;hold on;
figure(1)
plot(k,M,'ro');
title(' CONSTANTE Vs MOLARIDAD ');
xlabel('CONSTANTE ');ylabel('MOLARIDAD (M)');
grid on;hold on;
figure(2)
plot(k,t,'ko');
title(' CONSTANTE Vs TIEMPO (seg) ');
xlabel(' CONSTANTE ');ylabel('TIEMPO (seg)');
end
disp('......................FIN DEL PROGRAMA.....................');
9.-
%Programa para hallar el campo eléctrico que existe entre 2
cargas
clear memory
clc
disp('-------------------------------------------------------
----------------')
disp('PROGRAMA PARA HALLAR EL CAMPO ELECTRICO ENTRE DOS
CARGAS PUNTUALES');
disp('_____________________EN EL CURSO DE FISICA
II________________________')
disp('-------------------------------------------------------
----------------')
Q=input('ingrese carga (Q) en coulomb(C): ');
d=input('ingrese la distancia en metros(m): ');
while d<0;
d=input('ingrese distancia mayor que cero: ');
end
k=9*10^9;
E=(k*abs(Q))/d^2;
disp(' -----------------------')
fprintf('E=%5.9f\n',E)
disp(' -----------------------')

10.-
clc,clear all
disp('-------------------------------------------------------------------
-----------------')
disp('--- Halla la recta en forma
paramétrica------------------------------------------------')
%Nos permite representar una curva o superficie mediante una variable
llamada parámetro
disp('-----------------------
[p=po+E*a]-------------------------------------------------------------')
po=input('ingrese el punto de paso:');
while po<=0;
disp('ingrese el punto de paso mayor a cero');
po=input('ingrese el punto de paso:');
end
t=input('ingrese t:');
while t<0;
disp('ingrese el t positivo');
t=input('ingrese t :');
end
a=input('vector direccional:');
while a<0,
disp('ingrese el vector direccional positivo');
a=input('ingrese el vector direccional:');
end
format bank
disp(' t parámetro ');
for E=0:t;
p=po+E*a;%forma de la ecuación paramétrica
disp([ E p ])
end
x=[0:5:E];
y=x.*a+po;
plot(x,y,'r*');title('ecuación paramétrica');xlabel('t');ylabel('el
parámetro')
axis([0 50 0 2000])
hold on
grid on

También podría gustarte