Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
FACULTAD DE INGENIERA
QUMICA
LENGUAJES DE
PROGRAMACION
CATEDRTICO:
PRESENTADO POR:
DEDICATORIA
El presente trabajo lo dedico a todos
los ingenieros de la Facultad de
Ingeniera Qumica por la enseanza
que nos brindan.
Ejercicio 1
%PROGRAMA PARA OBTENER LA DERIVADA
clc;
disp('==================================================')
disp('-----------------***OBTENCION DE LA DERIVADA***---------------')
disp('---Y GRAFICAS DE LAS FUNCIONES: INICIAL Y DERIVADA---)
disp('==================================================')
syms x y
SALIDA:
===================================================
----------------***OBTENCION DE LA DERIVADA***---------------------Y GRAFICAS DE LAS FUNCIONES: INICIAL Y DERIVADA---===================================================
ingrese funcion:3*x+x^2
A=
3*x+x^2
la derivada de la funcion ser:
3+2*x
A continuacion se mostrarn las graficas:
Primero de la Funcion inicial
Luego de la funcion derivada
Ejercicio 2
%PROGRAMA PARA HALLAR DERIVADAS PARCIALES y SU GRAFICA
clc;
disp('=================================================')
disp('---------------------OBTENCION DE LA DERIVADA-------------------')
disp('----------------------PARCIAL RESPECTO A X e Y----------------------')
disp('=================================================')
syms x y z
A=input('ingrese funcion:');
B=diff(A,x)
C=diff(A,y)
disp('la derivada respecto a x es:'),;
disp(diff(A,x))
%calcula la derivada parcial respecto a X
disp('la derivada respecto a y es:');
disp(diff(A,y))
%calcula la derivada parcial respecto a y
subplot(1,2,1), ezplot(z-B) %la funcion ezplot muestra el grafico panoramico de la funcion
subplot(1,2,2), ezplot(z-C) %El ezplot muestra el titulo por defecto
SALIDA:
===================================================
---------------------OBTENCION DE LA DERIVADA--------------------------------------------PARCIAL RESPECTO A X e Y-----------------------===================================================
ingrese funcion:x^2+y^3
la derivada respecto a x es:
2*x
la derivada respecto a y es:
3*y^2
Ejercicio 3
%METODO de NEWTON RAPHSON mas rpido converge la funcin(llega a la
solucion)
clc;
disp('===========================================')
disp('-------------* METODO DE NEWTON RAPHSON *---------')
disp('===========================================')
nombre_f=input(' ingrese funcin asociada f(x)=','s');
x0=input(' ingrese valor inicial:');
fprintf('\n');
fprintf('iter aproximacin g(x) error\n');
i=1;e=1;delta=0.001;
while e>=3E-12 & i<=18
x=x0;
fx0=eval(nombre_f);
x=x0-delta;
df1=eval(nombre_f);
x=x0+delta;
df2=eval(nombre_f);
dfx0=(df2-df1)/(2*delta);
r=x0-(fx0/dfx0);
e=abs((r-x0)/r);
fprintf('%3.0f %10.6f %10.6f %10.6f\n',i,x0,r,e);
x0=r;
i=i+1;
end
disp('-----------------------------------------')
fprintf('
la raiz es:%10.9f\n',x0);
disp('-----------------------------------------')
SALIDA:
===================================================
-------------------*METODO DE NEWTON RAPHSON*-----------------===================================================
ingrese funcion asociada f(x)=5*x - x^3
ingrese valor inicial:2
iter aproximacin g(x) error
1 2.000000 2.285714 0.125000
2 2.285714 2.237640 0.021484
3 2.237640 2.236070 0.000702
4 2.236070 2.236068 0.000001
5 2.236068 2.236068 0.000000
---------------------------------------------la raiz es:2.236067977
--------------------------------------------->>
Ejercicio 4
%METODO de VONN MISSES
clc;
disp('==========================================')
disp('---------------* METODO DE VONN MISSES *-------------')
disp('==========================================')
nombre_f=input(' ingrese funcion asociada f(x)=','s');
x0=input(' ingrese valor inicial:');
fprintf('\n');
fprintf('iter aproximacion g(x) error\n');
i=1;e=1;delta=0.001;
x=x0;
fx0=eval(nombre_f);
x=x0-delta;
df1=eval(nombre_f);
x=x0+delta;
df2=eval(nombre_f);
dfx0=(df2-df1)/(2*delta);
while e>=3E-12 & i<=500
x=x0;
fx0=eval(nombre_f);
r=x0-(fx0/dfx0);
e=abs((r-x0)/r);
fprintf('%3.0f %10.6f %10.6f %10.6f\n',i,x0,r,e);
x0=r;
i=i+1;
end
disp('-----------------------------------------')
fprintf('
la raiz es:%10.9f\n',x0);
disp('-----------------------------------------')
SALIDA:
===================================================
-----------------------* METODO DE VONN MISSES *-------------------===================================================
ingrese funcion asociada f(x)=5*x-x^3
ingrese valor inicial:2
iter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
aproximacion g(x)
2.000000 2.285714
2.285714 2.212412
2.212412 2.245672
2.245672 2.231863
2.231863 2.237853
2.237853 2.235300
2.235300 2.236397
2.236397 2.235927
2.235927 2.236128
2.236128 2.236042
2.236042 2.236079
2.236079 2.236063
2.236063 2.236070
2.236070 2.236067
2.236067 2.236068
2.236068 2.236068
2.236068 2.236068
2.236068 2.236068
error
0.125000
0.033132
0.014811
0.006187
0.002676
0.001142
0.000490
0.000210
0.000090
0.000039
0.000017
0.000007
0.000003
0.000001
0.000001
0.000000
0.000000
0.000000
B=
4
ingrese segundo limite:2
C=
2
---------------------------------La solucin es: 32.459380
---------------------------------Ejercicio 6
%METODO DEL PUNTO FIJO
clc;
disp('=====================================================')
disp('--------------------------* METODO DEL PUNTO FIJO *----------------------')
disp('=====================================================')
clear
format short
F=input('ingrese funcin:','s');
x0=input('ingrese aproximacin inicial:');
T=input('ingrese tolerancia de error:');
N=input('ingrese nmero mximo de iteraciones:');
a1=subs(F,x0);
a2=subs(F,a1);
if abs(a1-x0) <= abs(a2-a1)
'el mtodo no converger'
break
else
'Felicidades el mtodo a convergido
end
i=1;
x1=subs(F,x0);
while abs(x1-x0)>T & i<N;
x0=x1;
x1=subs(F,x0);
i=i+1;
end
if i==N
fprintf('el mtodo fracas despus de %2.0f iteraciones',i)
else
fprintf('el mtodo tuvo xito despus de %2.0f iteraciones',i)
fprintf('\n')
fprintf( ' iter Aproximacin Raz')
fprintf('\n')
disp([ i x0 x1])
end
SALIDA:
==================================================
----------------------* METODO DEL PUNTO FIJO *---------------------==================================================
ingrese funcin:x^2
ingrese aproximacin inicial:0.01
ingrese tolerancia de error:0.001
ingrese nmero mximo de iteraciones:50
ans =
Felicidades el metodo a convergido
el mtodo tuvo xito despues de 2 iteraciones
iter Aproximacion Raiz
2.0000 0.0001 0.0000
Ejercicio 7
%Este programa sirve para hallar el siguiente la siguiente integral definida:
r=tan(a)-tan(b);
disp('el resultado de la integral es:')
disp(r)
end %FIN
disp('=====================================')
disp('PROGRAMA TERMINADO')
disp('=====================================')
SALIDA
==================================================
-----PROGRAMA PARA HALLAR LA INTEGRAL DE sen(ln x)---==================================================
ingrese el limite superior:5
ingrese el limite inferior:8
el resultado de la integral es:
3.4192
=====================================
PROGRAMA TERMINADO
=====================================
Ejercicio 8
%Este programa sirve para hallar la siguiente integral definida:
sec
xdx
=======================================================
ingrese el limite superior:5
ingrese el limite inferior:12
el resultado de la integral es:
2.7447
=====================
FIN DEL PROGRAMA
=====================
Ejercicio 9
%este programa sirve para hallar el siguiente la siguiente integral definida :
sen (ln
x ) dx
SALIDA:
=================================================
----PROGRAMA PARA HALLAR LA INTEGRAL DE sen(ln x)--=================================================
ingrese el limite superior:5
ingrese el limite inferior:8
el resultado de la integral es:
3.4192
=====================
FIN DEL PROGRAMA
=====================
Ejercicio 10
Ejercicio 12
clc;
disp('==============================================
===')
disp('------ - - - - - - - - - - - - - - - - - - * METODO DE SIMPSON *- - - - - - - - - - - - - - - - - - - - - - - - - ' )
disp('==============================================
===')
f=input('ingrese la funcin integral f(x)=','s');
a=input('ingrese limite inferior:');
b=input('ingrese limite superior:');
fprintf('ingrees numero de trapecios a \n');
n=input('considerar en la integracin:')
n=2*n;xmin=a-1; xmax=b+1;
h=(b-a)/n;
x=a:h:b;
fx=eval(f);y=abs(fx);
suma1=y(1)+y(n+1);suma2=3*sum(y(2:3:n-1));
suma3=3*sum(y(3:3:n));suma4=2*sum(y(4:3:n-2));
suma=suma1+suma2+suma3+suma4;
integral=(3/4)*h*suma;
fprintf('El area es:%10.9f\n',integral);
%grafica
xp=xmin:0.2:xmax;
x=xp
yp=eval(f);
plot(xp,yp,'g');
hold on
x=a:0.05:b;
y=eval(f);
bar(x,y,'r');
grid on
SALIDA:
==============================================
----------------------* METODO DE SIMPSON *-------------------==============================================
ingrese la funcion integral f(x)=sqrt(x.^5+x.*3+2)
ingrese limite inferior:2
ingrese limite superior:4
ingrees numero de trapecios a
considerar en la integracion:40
n=
40
El area es:65.038996358
x = Columns 1 through 6
1.0000 1.2000 1.4000 1.6000 1.8000 2.0000
Columns 7 through 12
2.2000 2.4000 2.6000 2.8000 3.0000 3.2000
Columns 13 through 18
3.4000 3.6000 3.8000 4.0000 4.2000 4.4000
Columns 19 through 21
4.6000 4.8000 5.0000
Ejercicio 13
%programa para determinar la raz de una funcin por el mtodo de la secante
clc;
disp('==============================================
====')
disp('--------------------------* METODO DE LA SECANTE *--------------------')
disp('==============================================
====')
format bank
F=input('ingrese funcin:','s');
x0=input('ingrese primera aproximacin inicial:');
x1=input('ingrese segunda aproximacin inicial:');
SALIDA:
===========================================
----------------* METODO DE LA SECANTE *--------------===========================================
ingrese funcin:sqrt(x)+2*x
ingrese primera aproximacin inicial:1
ingrese segunda aproximacin inicial:4
ingrese tolerancia de error:0.001
ingrese nmero mximo de iteraciones:1000
El mtodo tuvo xito despues de 50 iteraciones
-------------------------------------------------------------------iteraciones.......g(x)..........error
50.00
-0.00
0.00
--------------------------------------------------------------------
Ejercicio 14
clc, clear al l
disp('==============================================
===========')
disp('------------* Mtodo Numrico Aproximacin por Mnimos Cuadrados *--------')
disp('==============================================
===========')
N=input(' Ingrese el grado de polinomio a aproximar: ');
X=input(' Ingrese los valores x(i): ');
F=input(' Ingrese los valores f(xi): ');
M=length(X);
A=zeros(N+1);
H=zeros(N+1,N+1);
A(1,1)=M;
for l=1:2*N;
s(l)=sum((X.^l));
end
for l=0:N;
b(l+1)=sum(F.*(X.^l));
end
A(1,2:N+1)=s(1:N);
for l=2:N+1;
A(l,1:N+1)=s(l-1:N+l-1);
end
b=b';
DET=1;
I=1;
format short
while I<=(N)
DET=DET*A(I,I);
if DET == 0
disp( '
"Hay un 0 en la diagonal pr inc ipa l " ' ) ;
break
else
K=I+1;
while K<=N+1
J=I+1;
while J<=N+1
A(K,J)=A(K,J)-A(K,I)*A(I,J)/A(I,I);
J=J+1;
H(K:N+1,I)=A(K:N+1,I);
end
b(K)=b(K)-A(K,I)*b(I)/A(I,I);
K=K+1;
end
I=I+1;
end
end
B=A;
A=A-H;
DET=DET*A(N+1,N+1);
if DET==0
disp(' "Hay un 0 en la diagonal principal" ');
break
else
x(N+1)=b(N+1)/A(N+1,N+1);
I=N;
end
while I>=1
x(I)=b(I);
J=1+I;
while J<=N+1
x(I)=x(I)-A(I,J)*x(J);
J=J+1;
end
x(I)=x(I)/A(I,I);
I=I-1;
end
disp(' ')
disp('-----------------------------------------')
disp(' Solucin: ')
for l=0:N;
fprintf(' El coeficiente (%d) es: %f\n',l,x(l+1))
disp('-----------------------------------------')
end
SALIDA:
====================================================
------* Mtodo Numrico Aproximacin por Mnimos Cuadrados *------====================================================
Ingrese el grado de polinomio a aproximar: 3
Ingrese los valores x(i): [-1 0 1 2]
Ingrese los valores f(xi): [4 8 16 34]
--------------------------------------------------Solucin:
El coeficiente (0) es: 8.000000
El coeficiente (1) es: 5.000000
El coeficiente (2) es: 2.000000
El coeficiente (3) es: 1.000000
--------------------------------------------------Ejercicio 15
% programa para realizar el ajuste a curvas de la parbola.
clc
disp('========================================================')
disp('----* PROGRAMA PARA HACER EL AJUSTE DE CURVAS DE LA * ----')
disp('-------------------------------* PARABOLA *--------------------------------------------')
disp('========================================================')
a=input('ingrese la matriz a:');
b=input('ingrese la matriz b:');
c=sum(a);
d=sum(a.^2);
e=sum(a.^3);
f=sum(a.^4);
g=sum(b);
h=sum(a.*b);
i=sum((a.^2).*b);
x=inv([11,c,d;c,d,e;d,e,f])*[g;h;i]
SALIDA:
====================================================
----* PROGRAMA PARA HACER EL AJUSTE DE CURVAS DE LA *-----------------------------------* PARBOLA *-----------------------------------====================================================
Ejercicio 17
%Este programa sirve para hacer el ajuste de curvas de un " polinomio de tercer
grado"
clc
disp('=========================================================')
disp('--* PROGRAMA HACER EL AJUSTE DE CURVAS DE UN POLINOMIO *--')
disp('----------------------------------* DE TERCER GRADO *----------------------------------')
disp('=========================================================')
pero ejemplo x^3 +x-2=0
a=input('ingrese la matriz a:');
b=input('ingrese la matriz b:');
c=sum(a);
d=sum(a.^2);
e=sum(a.^3);
f=sum(a.^4);
h=sum(a.^5);
i=sum(a.^6);
j=sum(b);
k=sum(a.*b);
l=sum((a.^2).*b);
m=sum((a.^3).*b);
x=inv([11,c,d,e;c,d,e,f;d,e,f,h;e,f,h,i])*[j;k;l;m]
SALIDA:
=========================================================
--* PROGRAMA HACER EL AJUSTE DE CURVAS DE UN POLINOMIO *---------------------------------- * DE TERCER GRADO * -------------------------------==========================================================
ingrese la matriz a:[0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1]
ingrese la matriz b:
[0,0.1002,0.2013,0.3045,0.4108,0.5211,0.6367,0.7586,0.8881,1.0265,1.1752]
x=
-0.0001
1.0046
-0.0201
0.1907
Ejercicio 18
%PROGRAMA PARA HALLAR LA RAIZ DE UN SISTEMA DE ECUACIONES
%POR EL METODO DE LA BISECCION
disp('==============================================
================')
disp('------------------------------------* MTODO DE LA BISECCION
*----------------------------')
disp('-------------------------------- ---* PARA DETERMINAR RAICES *----------------------------')
disp('==============================================
================')
fprintf(\n);
nombre_f=input(
ingrese funcion asociada f(x)= ,s);
a=input( ingrese limite inferior: );
b=input( ingrese limite superior: );
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; f r=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);
fpr in t f ( %10.6f\n , e ) ;
end
i=i+1;
end
disp('------------------------------------------------------------')
fprintf('\n'); fprintf('la raiz es: %10.9f\n', r);
disp('------------------------------------------------------------')
SALIDA:
==================================================
======
--------------------------* MTODO DE LA BISECCION *------------------------------------------------- ---* PARA DETERMINAR RAICES *---------------------------==================================================
======
Ejercicio 19
%POR EL METODO DE LA REGLA FALSA
disp('==============================================
==================')
disp('------------------------------------------------------------')
fprintf('\n'); fprintf('la raiz es: %10.9f\n', r);
disp('------------------------------------------------------------')
SALIDA:
=============================================
=================
--------------------------------* MTODO DE LA REGLA FALSA *---------------------------=============================================
=================
b
6.000000
aprox
4.000000
6.000000
5.000000
6.000000
5.500000
error
4 5.500000
6.000000 5.750000
0.043478
5 5.750000
6.000000 5.875000
0.021277
6 5.875000
6.000000 5.937500
0.010526
7 5.937500
6.000000 5.968750
0.005236
8 5.968750
6.000000 5.984375
0.002611
9 5.984375
6.000000 5.992188
0.001304
10 5.992188
6.000000 5.996094
0.000651
-------------------------------------------------------------la raiz es: 5.996093750
-------------------------------------------------------------Ejercicio 20
%METODO DEL PUNTO FIJO
disp('==============================================
=======')
disp('---------------------------* MTODO DEL PUNTO FIJO *-----------------------')
disp('==============================================
=======')
clc;
fprintf('\n');
nombre_f=input('
ingrese funcion asociada \n');
nombre_f=input('
al punto fijo g(x)=','s');
x0=input(' ingrese valor inicial : ');
fprintf('\n');
fprintf(' it
aprox
g(x)
error\n');
i=1;e=1;
while e>=3E-6 & i<=18
x=x0;
r=eval(nombre_f);
e=abs((r-x0)/r);
fprintf(' %3.0f %10.6f %10.6f %10.6f\n',i,x0,r,e);
x0=r;
i=i+1;
end
disp('------------------------------------------------------------')
fprintf('la raiz es: %10.9f\n', x0);
disp('------------------------------------------------------------')
SALIDA:
=============================================
========
---------------------------* MTODO DEL PUNTO FIJO *----------------------=============================================
========
disp('------------------------------------------------------------')
disp(las raices son:)
disp([raiz1 raiz2])
disp('------------------------------------------------------------')
SALIDA:
==================================================
========
---------------------------* DETERMINACION DE RAICES *------------------------------------------* PARA UNA ECUACION DE SEGUNDO GRADO *----------------==================================================
========
ingrese el coeficiente cuadratico:2
ingrese el coeficiente del termino lineal:14
ingrese el termino independiente:4
------------------------------------------------------------