Documentos de Académico
Documentos de Profesional
Documentos de Cultura
i x y
--------------------------------
1 0.000000 0.000000
2 0.800000 0.880000
3 0.991787 0.991712
4 0.999975 0.999969
5 1.000000 1.000000
n xk yk d
METODO DE BROYDEN
clear all;clc
format long
syms x
syms y
a1=0.25;a2=1-a1;b1=1.12;b2=1.6;
f1=log(a1+x*a2)+a2*(x/(a1+x*a2)-y/(a2+y*a1))-log(b1);
%Ingresar ecuacion 1
f2=log(a2+y*a1)-a1*(x/(a1+x*a2)-y/(a2+y*a1))-log(b2);
%Ingresar ecuacion 2
f3=diff(f1,x);f4=diff(f1,y);
f5=diff(f2,x);f6=diff(f2,y);
e=10^-5;
m=1;
d=1;
x1(m)=0;
y1(m)=0;
while d>e %Metodo Newton-Rahpson
x=x1(m);
y=y1(m);
A=[eval(f3),eval(f4);eval(f5),eval(f6)];
B=[-eval(f1);-eval(f2)];
c=inv(A)*B;
h=c(1);k=c(2);
x1(m+1)=x1(m)+h;
y1(m+1)=y1(m)+k;
d(m+1)=((x1(m+1)-x1(m))^2+(y1(m+1)-y1(m))^2)^0.5;
m=m+1;
end
m=1; %Metodo de Broyden
d=1;
x2(m)=0;
y2(m)=0;d=1;
x=x2(m);
y=y2(m);
J=[eval(f3),eval(f4);eval(f5),eval(f6)];
F0=[eval(f1);eval(f2)];
X0=[x2(m);y2(m)];
X1=X0-inv(J)*F0;
x2(m+1)=X1(1);y2(m+1)=X1(2);
A0=inv(J);
while d>e
x=x2(m);y=y2(m);X0=[x2(m);y2(m)];
F0=[eval(f1);eval(f2)];
x=x2(m+1);y=y2(m+1);X1=[x2(m+1);y2(m+1)];
F1=[eval(f1);eval(f2)];
Ax=X1-X0;
AF=F1-F0;
if m==1
A1=A0+((Ax-A0*AF)*(Ax')*A0)/((Ax')*A0*AF);
X2=X1-A1*F1;
x2(m+2)=X2(1);y2(m+2)=X2(2);
else
A2=A1+((Ax-A1*AF)*(Ax')*A1)/((Ax')*A1*AF);
X2=X1-A2*F1;
x2(m+2)=X2(1);y2(m+2)=X2(2);
end
d(m+1)=((x2(m+2)-x2(m+1))^2+(y2(m+2)-y2(m+1))^2)^2;
m=m+1;
end
disp('Metodo de Broyden')
disp('i x y')
disp('--------------------------------')
for a=1:1:m
fprintf('%d %f %f\n',a,x2(a),y2(a))
end
Metodo de Broyden
i x y
--------------------------------
1 0.000000 0.000000
2 0.585811 2.015246
3 0.919488 2.623781
4 1.170546 2.813768
5 1.343683 2.785459
6 1.888736 2.558188
7 2.094750 2.444740
METODO LAGRANGE
function program_diferenciasfinitas
%diferencias finitas hacia adelante
clc,clear
x=[40 50 60 70 80]
fx=[922.5 988.02 983.13 977.63 971.6]
n=5;
h=10;
xint=48;
for i=1:n-1
t(i,1)=fx(i+1)-fx(i)
end
for j=2:n-1
for i=j:n-1
t(i,j)=t(i,j-1)-t(i-1,j-1)
end
end
for k=3:n-1
for i=k:n-1
t(i,k)=t(i,k-1)-t(i-1,k-1)
end
end
s=(xint-x(1))/h
fxint=fx(1)+s*t(1,1)
fprintf('grado 1 p(%4.0f)=%6.2f \n',xint,fxint)
fxint=fx(1)+s*t(1,1)+s*(s-1)/2*t(2,2)
fprintf('grado 2 p(%4.0f)=%6.2f \n',xint,fxint)
fxint=fx(1)+s*t(1,1)+s*(s-1)/2*t(2,2)+s*(s-1)*(s-2)/6*t(3,3)
fprintf('grado 3 p(%4.0f)=%6.2f \n',xint,fxint)
fxint=fx(1)+s*t(1,1)+s*(s-1)/2*t(2,2)+s*(s-1)*(s-2)/6*t(3,3)+s*(s-1)*(s-
2)*(s-3)/8*t(4,4)
fprintf('grado 4 p(%4.0f)=%6.2f \n',xint,fxint)
fxint=fx(1)+s*t(1,1)+s*(s-1)/2*t(2,2)+s*(s-1)*(s-2)/6*t(3,3)+s*(s-1)*(s-
2)*(s-3)/8*t(4,4)
fprintf('grado 5 p(%4.0f)=%6.2f \n',xint,fxint)
fxint=fx(1)+s*t(1,1)+s*(s-1)/2*t(2,2)+s*(s-1)*(s-2)/6*t(3,3)+s*(s-1)*(s-
2)*(s-3)/8*t(4,4)+s*(s-1)*(s-2)*(s-3)*(s-4)/10*t(4,4)
x=
40 50 60 70 80
fx =
1.0e+02 *
t=
65.519999999999982
t=
65.519999999999982
-4.889999999999986
t=
65.519999999999982
-4.889999999999986
-5.50000000000000
t=
65.519999999999982
-4.889999999999986
-5.500000000000000
-6.029999999999973
t=
65.519999999999982 0
-4.889999999999986 -70.409999999999968
-5.500000000000000 0
-6.029999999999973 0
t=
65.519999999999982 0
-4.889999999999986 -70.409999999999968
-5.500000000000000 -0.610000000000014
-6.029999999999973 0
t=
65.519999999999982 0
-4.889999999999986 -70.409999999999968
-5.500000000000000 -0.610000000000014
-6.029999999999973 -0.529999999999973
t=
65.519999999999982 0 0
-4.889999999999986 -70.409999999999968 0
-6.029999999999973 -0.529999999999973 0
t=
65.519999999999982 0 0
-4.889999999999986 -70.409999999999968 0
t=
65.519999999999982 0 0 0
-4.889999999999986 -70.409999999999968 0 0
t=
65.519999999999982 0 0 0
-4.889999999999986 -70.409999999999968 0 0
t=
65.519999999999982 0 0 0
-4.889999999999986 -70.409999999999968 0 0
t=
65.519999999999982 0 0 0
-4.889999999999986 -70.409999999999968 0 0
s=
0.800000000000000
fxint =
9.749159999999999e+02
grado 1 p( 48)=974.92
fxint =
9.805487999999999e+02
grado 2 p( 48)=980.55
fxint =
9.827823999999999e+02
grado 3 p( 48)=982.78
fxint =
9.864636159999999e+02
grado 4 p( 48)=986.46
fxint =
9.864636159999999e+02
grado 5 p( 48)=986.46
fxint =
9.770397030400000e+02
METODO SIMPSON
clc,clear
syms x
a=-1;
b=1;
for i=1:11
n=2^(i-1);
h=(b-a)/n;
x=a;
s=0;
if n>1
for j=1:n-1
x=x+h;
f=1/sqrt(2*pi)*exp(-x^2/2);
s=f+s;
end
end
fa=1/sqrt(2*pi)*exp(-a^2/2);
fb=1/sqrt(2*pi)*exp(-b^2/2);
s=h/2*(fa+2*s+fb);
e=abs(0.682689-s)/s*100;
fprintf('%4d %8.6f %8.6f \n',n,s,e)
end
1 0.483941 41.068512
2 0.640913 6.518201
4 0.672522 1.511798
8 0.680164 0.371280
16 0.682059 0.092363
32 0.682532 0.023012
64 0.682650 0.005697