Está en la página 1de 19

1.

-
CODIGO APLICANDO METODO DE PUNTO FIJO
clear all
close all
clc

%codigo del metodo de punto fijo

xi=4; % cuando i es un valor propuesto 0


Niter=1e3;
tol=1e-3;

for i=1:Niter
%xn=((-0.1*sin(xi))/(exp(xi)))
%xn=log((-0.1*sin(xi))/xi)
%xn=asin(-xi/0.1*exp(-xi))
xn=xi*exp(-xi)+0.1*sin(xi)+xi

error=abs((xn-xi)/xn)*100
figure(1)
semilogy(i,error,'or'), grid on, hold on
xlabel('iteraciones 1'), ylabel('% error'), title('METODO DE PUNTO FIJO')
if error<tol
disp('Solucion encontrada')
solf=xn;
errorf=error;
iterf=i
break
end
xi=xn;
end

CODIGO APLICANDO METODO DE NEWTON RAPHSON


clear all
close all
clc

xi=2;
tol=1e-3;
niter=1e3;

for i=1:niter

fx=xi*exp(-xi)+0.1*sin(xi)
dfx=-xi*exp(-xi)+exp(-xi)+0.1*cos(xi)

% ec de NR
xn=xi-fx/dfx;

error=abs((xn-xi)/xn)*100;

figure(1)
semilogy(i,error,'or'), grid on, hold on
xlabel('iteraciones 1'), ylabel('% error'), title('METODO DE NEWTON-RAPHSON')

if error<tol
disp('Solucion encontrada')
soluf=xn;
errorf=error
iterf=i,
break
end
xi=xn
end

2.-
Interaciones xi xi+1 % error
1 4 3.9975823 0.0604789
2 3.9975823 3.9954558 0.0532227
3 3.9954558 3.993586 0.0468205
4 3.993586 3.9919423 0.0411757
5 3.9919423 3.9904977 0.0362014
6 3.9904977 3.9892283 0.0318205
7 3.9892283 3.988113 0.0279638
8 3.988113 3.9871334 0.02457
9 3.9871334 3.986273 0.0215845
10 3.986273 3.9855174 0.0189591
11 3.9855174 3.9848539 0.0166509
12 3.9848539 3.9842713 0.0146222
13 3.9842713 3.9837598 0.0128393
14 3.9837598 3.9833107 0.0112729
15 3.9833107 3.9829166 0.0098969
16 3.9829166 3.9825705 0.0086882
17 3.9825705 3.9822668 0.0076267
18 3.9822668 3.9820003 0.0066946
19 3.9820003 3.9817663 0.0058761
20 3.9817663 3.9815609 0.0051575
21 3.9815609 3.9813807 0.0045266
22 3.9813807 3.9812225 0.0039728
23 3.9812225 3.9810837 0.0034866
24 3.9810837 3.9809619 0.0030599
25 3.9809619 3.980855 0.0026853
26 3.980855 3.9807612 0.0023566
27 3.9807612 3.9806789 0.002068
28 3.9806789 3.9806066 0.0018148
29 3.9806066 3.9805433 0.0015926
30 3.9805433 3.9804876 0.0013975
31 3.9804876 3.9804388 0.0012263
32 3.9804388 3.980396 0.0010761
33 3.980396 3.9803584 0.0009443
3.-

4.-
RESULTADOS APLICANDO PUNTO FIJO
xn =
3.9804
error =
9.4432e-04
Solucion encontrada
iterf =
33
RESULTADOS APLICANDO NEWTON-RAPHSON
xi =
3.9801
fx =
2.1688e-07
dfx =
-0.1225
Solucion encontrada
errorf =
4.4468e-05
iterf =
4
1.-
CODIGO APLICANDO METODO DE PUNTO FIJO
clear all
close all
clc

%codigo del metodo de punto fijo

xi=1; % cuando i es un valor propuesto 0


Niter=1e3;
tol=1e-3;

for i=1:Niter
%xn=exp(sqrt(xi))
%xn=(log(xi))^2
xn=exp(sqrt(xi))-xi+xi

error=abs((xn-xi)/xn)*100
figure(1)
semilogy(i,error,'or'), grid on, hold on
xlabel('iteraciones 1'), ylabel('% error'), title('METODO DE PUNTO FIJO')
if error<tol
disp('Solucion encontrada')
solf=xn;
errorf=error;
iterf=i
break
end
xi=xn;
end
CODIGO APLICANDO METODO DE NEWTON RAPHSON
clear all
close all
clc

xi=1;
tol=1e-3;
niter=1e3;

for i=1:niter

fx=exp(sqrt(xi))-xi
dfx=exp(sqrt(xi))/2*xi^0.5

% ec de NR
xn=xi-fx/dfx;

error=abs((xn-xi)/xn)*100;

figure(1)
semilogy(i,error,'or'), grid on, hold on
xlabel('iteraciones 1'), ylabel('% error'), title('METODO DE NEWTON-RAPHSON')

if error<tol
disp('Solucion encontrada')
soluf=xn;
errorf=error
iterf=i,
break
end
xi=xn
end
2.-
Para este caso encontramos que hay solucion si aplicamos el metodo de punto fijo pero si aplicamos el
metodo de Newton-Raphson ahí encontramos solucion pero las raices son imaginarias por lo que tampoco son
soluciones fisicas que son las que buscamos y es por ello que no se puede poner el punto 3 y 4.
1. CODIGO APLICANDO METODO DE NEWTON RAPHSON
2. clear all
3. close all
4. clc
5.
6. xi=5;
7. tol=1e-3;
8. niter=1e3;
9.
10. for i=1:niter
11.
12. fx=(668.061/xi*(1-exp(-xi/68.1*10)))-40
13. dfx=(-668.061/xi^2)+((98.1/xi)*exp((-10*xi)/68.1))+((668.061/xi^2)*exp((-10*xi)/68.1))
14. % ec de NR
15. xn=xi-fx/dfx;
16.
17. error=abs((xn-xi)/xn)*100;
18.
19. figure(1)
20. semilogy(i,error,'or'), grid on, hold on
21. xlabel('iteraciones 1'), ylabel('% error'), title('METODO DE NEWTON-RAPHSON')
22.
23. if error<tol
24. disp('Solucion encontrada')
25. soluf=xn;
26. errorf=error
27. iterf=i,
28. break
29. end
30. xi=xn
31. end
3.-

4.-
1.-
clear all
close all
clc

x0=.1;
y0=5;
niter=1000;
Tol=1e-3;

for i=1:niter
X0=[x0;y0];
J=[2*x0+y0,x0;3*y0^2, 1+6*x0*y0];
F=[x0^2+x0*y0-10;y0+3*x0*y0^2-57];
Xn=-J^-1*F+X0
Error=sum(abs((Xn-X0)/(Xn)))*100
figure(1)
semilogy(i,Error,'or')
xlabel('iteaciones'), ylabel('%Error'), title('PROBLEMA 5')
if Error<Tol
disp('sol encontrada')
Xsol=Xn, Errorf=Error, iterf=i
break
end
x0=Xn(1), y0=Xn(2)
end
3.-

4.-
Xsol=
2.0000
3.0000
Errorf=
0
1.31605764286391e-05
iterf =
31
clear all
close all
clc

a=1
b=1
c=1
d=1
m=1
Or=3

if Or==1
x=0:0.1:20
[y]=poli_primer_orden(x,m,b);
figure(1)
plot(x,y),grid on,hold on
xlabel('eje x'), ylabel('eje y')
elseif Or==2
x=0:0.1:20
[y]=poli_segundo_orden(a,b,x,c);
figure(2)
plot(x,y),grid on,hold on
xlabel('eje x'), ylabel('eje y')
else Or==3
x=0:0.1:20
[y]=poli_tercer_orden(x,a,b,c,d)
figure(3)
plot(x,y),grid on,hold on
xlabel('eje x'), ylabel('eje y')
end
SECUNDARIO TERCIARIO Y CUATERNARIO
function [y]=poli_primera_orden(x,m,b)
y=m*x+b
function[y]=poli_segundo_orden(a,b,x,c)
y=a.*x.^2+b.*x+c
function [y]=poli_tercer_orden(x,a,b,c,d)
y=a.*x.^3+b.*x.^2+c.*x+d
CODIGO DE MATLAB
clear all
close all
clc

H=zeros(10);
for i=1:10
for j=1:10
H(i,j)=1/(i+j-1)
end
end
1.-
CODIGO APLICANDO METODO GRAFICO
clear all
close all
clc

R=0.082054;
a=2.592;
b=0.04267;
P=1;
T=300;
n=1
V=0.1:0.1:40

y=((P+((a.*n.^2)./V.^2)).*((V./n)-b))-(R.*T);
% V=24.6 solución método gráfico
figure(1)
plot(V,y), grid on
xlabel('V')
ylabel('y')
R=0.082054;
a=2.592;
b=0.04267;
P=10;
T=300;
n=1
V=-0.10:0.1:20

y1=((P+((a.*n.^2)./V.^2)).*((V./n)-b))-(R.*T);
%%V=2.4
figure(2)
plot(V,y1), grid on
xlabel('V')
ylabel('y1')
200

150

100
y1

50

-50

-100
-5 0 5 10 15 20
V

R=0.082054;
a=2.592;
b=0.04267;
P=100;
T=300;
n=1
V=0:0.01:1

y2=((P+((a.*n.^2)./V.^2)).*((V./n)-b))-(R.*T);
%%V=0.175
figure(3)
plot(V,y2), grid on
xlabel('V')
ylabel('y2')
100

-100

-200

-300
y2

-400

-500

-600

-700

-800

-900
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
V
2.-
CODIGO APLICANDO METODO PUNTO FIJO
3.-
CODIGO APLICANDO METODO NEWTON-RAPHSON
P=1
Vi=0.1;
tol=1e-3;
Niter=1e6;
for i=1:Niter
fV=((P+((a.*n.^2)./Vi.^2)).*((Vi./n)-b))-(R.*T);
dfV=(P./n)-((a.*n)./Vi.^2)+((2.*a.*b.*n.^2)./Vi.^3);
%Ecuacion de NR
Vn=Vi-dfV.^-1.*fV;
Error=abs((Vn-Vi)/Vn)*100;
figure(7)
semilogy(i,Error,'or'), grid on, hold on
xlabel('iteraciones')
ylabel('%Error')
if Error<tol
soluf=Vn, Error=Error, iterf=i,
break
end
Vi=Vn
end
%%%V=24.55 E=1.7816e-07% iteraciones=7
104

102

100
%Error

10-2

10-4

10-6

10-8
1 2 3 4 5 6 7
iteraciones
Vi=0.1;
tol=1e-3;
Niter=1e6;
for i=1:Niter
fV=((P+((a.*n.^2)./Vi.^2)).*((Vi./n)-b))-(R.*T);
dfV=(P./n)-((a.*n)./Vi.^2)+((2.*a.*b.*n.^2)./Vi.^3);
%Ecuacion de NR
Vn=Vi-dfV.^-1.*fV;
Error=abs((Vn-Vi)/Vn)*100;
figure(8)
semilogy(i,Error,'or'), grid on, hold on
xlabel('iteraciones')
ylabel('%Error')
if Error<tol
soluf=Vn, Error=Error, iterf=i,
break
end
Vi=Vn
end
%%%V=2.3981 E=4.5849e-4% iteraciones=6
103

102

101

100
%Error

10-1

10-2

10-3

10-4
1 1.5 2 2.5 3 3.5 4 4.5 5 5.5 6
iteraciones
Vi=0.1;
tol=1e-3;
Niter=1e6;
for i=1:Niter
fV=((P+((a.*n.^2)./Vi.^2)).*((Vi./n)-b))-(R.*T);
dfV=(P./n)-((a.*n)./Vi.^2)+((2.*a.*b.*n.^2)./Vi.^3);
%Ecuacion de NR
Vn=Vi-dfV.^-1.*fV;
Error=abs((Vn-Vi)/Vn)*100;
figure(9)
semilogy(i,Error,'or'), grid on, hold on
xlabel('iteraciones')
ylabel('%Error')
if Error<tol
soluf=Vn, Error=Error, iterf=i,
break
end
Vi=Vn
end
%%%V=0.1782 E=0.00022% iteraciones=4

También podría gustarte