Está en la página 1de 1

Método jacobi código

%% datos de entrada
tam=size(B); %tamaño de la matriz A=[3 -0.1 -0.2;0.1 7 -0.3;0.3 -0.2 10];
n_max=1000; %número máxima de iteraciones b=[7.85 -19.3 71.4];
%%método gauss-simple%%
for iter=1: n_max %eliminación hacia adelante
for i=1: tam (1) %fila n=length(b);
sum=0;
for j=1: tam (2) %columna for j=1: n-1 %vector columna
if i==j for i=j+1: n %vector fila
continue pivote=A(i,j)/A(j,j);
else for z=j:n
sum=sum+B (i, j) *x0(j); A(i,z)=-pivote*A(j,z)+A(i,z);
end end
end b(i)=-pivote*b(j)+b(i);
x(i)=(r(i)-sum)/B (i, i); end
error(i)=abs(x(i)-x0(i))/x(i); end
end
if error<=tol
break
x0=x;
end
end
iter
x
error
método punto fijo

%% datos de entrada

x0=1.5; %valores iniciales


y0=3.5; %valores iniciales
tol=1e-3; %tolerancia
n=1000; %número máximo de iteraciones

%%método punto fijo%%

for i=1:n
x_new=sqrt(10-(x0*y0));
y_new=sqrt((57-y0)/(3*x_new));

e_x=abs((x_new-x0)/x_new);
e_y=abs((y_new-y0)/y_new);

if (e_x<=tol && e_y <=tol)


break
else
x0=x_new
y0=y_new
end
end
i
x_new
y_new
e_x
e_y

También podría gustarte