Você está na página 1de 4

METODO DE LA BISECCION

ENCONTRAR LA RAIZ
clc
clear all
format long
s='x.^3-x-13'
f=inline(s)
a=2,b=3; %intervalo que contiene una raiz
acum=[]; format long
for i=1:20
r=(a+b)/2; err=(b-a)/2;
acum=[acum;a r b err];
if f(a)*f(r)<0
b=r;
else
a=r;
end
end
raiz1=r
disp(acum)
raiz2=fzero(f,2.0)

ENCONTRAR EL INTERVALO DE LA RAIZ

clc
clear all
format long
s='x.^3-x-13'
f=inline(s)
x=-5:5;
y=f(x);
plot(x,y)
grid
disp([x' y']);
acum=[];
for i=1:length(x)-1
if y(i)*y(i+1)<0
acum=[acum;x(i) x(i+1)];
end
end
disp('Intervalos que continen raices')
disp(acum)

xxxxxxxxxxxxxxxxxxxxxxxxxx

clc
clear all
format long
s='0.0162+0.1*exp(0.41*x).*(cos(7.5*0.41)-(x.*sin(7.5*0.41))/7.5)'
f=inline(s)
x=-16:6;
y=f(x);
plot(x,y)
grid
disp([x' y']);
acum=[];
for i=1:length(x)-1
if y(i)*y(i+1)<0
acum=[acum;x(i) x(i+1)];
end
end
disp('Intervalos que continen raices')
disp(acum)

METODO DE NEWTON RHAPSON

DERIVADA DE UNA FUNCION

clear all
clc
syms x
f=0.0162+0.1*exp(0.41*x).*(cos(7.5*0.41)-(x.*sin(7.5*0.41))/7.5)
df_x=diff(f,x)

NEWTON

clc
clear all
%f(x)=x^3-x-13=0, buscando alternativas
%f'(x)=3*x^2-1
f=inline('0.0162+0.1*exp(0.41*x).*(cos(7.5*0.41)-
(x.*sin(7.5*0.41))/7.5)')
df=inline('-(1598320207760387*exp((41*x)/100))/1801439850948198400 -
(41*exp((41*x)/100)*((1598320207760387*x)/180143985094819840 +
8987235054471017/9007199254740992))/1000')
x=-4.375; acum=[];
for i=1:3
xn=x-f(x)/df(x);
err=abs(xn-x);
acum=[acum;xn err];
x=xn;
end
disp(acum)

LOCALIZACION DE LA RAIZ GRAFICAMENTE

CONVERGENCIA DEL PUNTO FIJO

% programa06.m
% Analisis de la Convergencia del punto fijo
clc, clear all
% x^3-x-13=0, buscando alternativas
% x=(x+13)^(1/3)=g1x) CONVERGE
% x=x^3-13 DIVERGE
% x=13/(x^2-1)
% x=(x+13)/x^2
% x=((x+13)/x)^(1/2)
t1='(x+13)^(1/3)'
dt1='1/3*(x+13)^(-2/3)'
f1=inline(dt1)
x=2.5; m=abs(f1(x))
% Converge si /g'(x0)/<1

CALCULO DE RAICES PUNTO FIJO

% programa05.m
% Calculo de raices de una ecuacion no lineal
% de una variable usando punto fijo
clc, clear all, s='x.^3-x-13', f=inline(s)
% x^3-x-13=0, buscando alternativas
% x=(x+13)^(1/3)=g1x) CONVERGE
% x=x^3-13 DIVERGE
% x=13/(x^2-1)
% x=(x+13)/x^2
% x=((x+13)/x)^(1/2)
t1='x^3-13', format long
g1=inline(t1)
x=2.5; acum=[];
for i=1:10
x1=g1(x);
err=abs(x1-x);
acum=[acum;x1 err];
x=x1;
end
% si el error disminuye habrá convergencia!!
disp(acum)

METODO JACOBI

%Programa 04
% Metodos de Jacobi Matricial
clc
clear all
A=[4 -1 1;-1 5 2;1 2 8], B=[4 6 11]', TOL=1e-3
D=diag(diag(A))
L=-tril(A)+D
U=-triu(A)+D
Tj=inv(D)*(L+U)
cj=inv(D)*B
x=zeros(size(B));tabla=[x' NaN];
for i=1:1000
xn=Tj*x+cj;
err=norm(xn-x,2)
tabla=[tabla; xn' err];
if err<TOL
break
end
x=xn;
end
disp(tabla)
NumIte=i
%Guardar en una tabla
GAUSS SEIDEL

% programa05.m
% Metodo de Gauss-Seidel Matricial
% Para Sistemas lineales iterativos
clc, clear all,
% A=[4 -1 1; -1 5 2;1 2 8], b=[4 6 11]',
A=input('A='), b=input('b=')
TOL=1e-3, format long
D=diag(diag(A))
L=D-tril(A)
U=D-triu(A)
Tg=inv(D-L)*U
Cg=inv(D-L)*b
x=zeros(size(b)); tabla=[x' NaN];
for i=1:1000
xn=Tg*x+Cg;
err=norm(xn-x,2);
tabla=[tabla;xn' err];
if err<TOL
break
end
x=xn;
end
if err<TOL
disp(tabla)
NumIte=i
else
Num=i % 1000
disp('Sistema Divergente!!!')
end

CRITERIO DE CONVERGENCIA

% programa06.m
% Criterio de convergencia
% Para Sistemas lineales iterativos
clc, clear all
A=input('A=')
D=diag(diag(A))
L=D-tril(A)
U=D-triu(A)
Tg=inv(D-L)*U
Tj=inv(D)*(L+U)
rhoj=max(abs(eig(Tj))) % eig calculo de valores propios
if rhoj<1
disp('Jacobi convergente!!!')
else
disp('Jacobi Divergente!!!')
end

Você também pode gostar