Als txt, pdf oder txt herunterladen
Als txt, pdf oder txt herunterladen
Sie sind auf Seite 1von 2

//AULA DE CALCULO NUMRICO USANDO O SCILAB

//MTODO_DE_GAUSS-JACOBI
clear// limpa todas variveis
clc// limpa o console
x1i=input('Entre com o valor de x1de0: ')
x2i=input('Entre com o valor de x2de0: ')
x3i=input('Entre com o valor de x3de0: ')
tol=input('Entre com o valor da Tolerncia: ')
printf("\n\n1 ITERAO")
x1f=((7-2*x2i-x3i)/10)
x2f=((-8-x1i-x3i)/5)
x3f=((6-2*x1i-3*x2i)/10)
itera=1
printf('\n x1(%g)=%g',itera,x1f)
printf('\n x2(%g)=%g',itera,x2f)
printf('\n x3(%g)=%g',itera,x3f)
while(abs(x1f-x1i)>tol|abs(x2f-x2i)>tol|abs(x3f-x3i)>tol)
a=abs(x1f-x1i)
b=abs(x2f-x2i)
c=abs(x3f-x3i)
printf("\n

Critrio de parada")

if(a>tol)
printf('\n

|%g-(%g)|=%g>%g',x1f,x1i,a,tol)

else
printf('\n

|%g-(%g)|=%g<%g',x1f,x1i,a,tol)

end
if(b>tol)
printf('\n

|%g-(%g)|=%g>%g',x2f,x2i,b,tol)

else
printf('\n

|%g-(%g)|=%g<%g',x2f,x2i,b,tol)

end
if(c>tol)
printf('\n

|%g-(%g)|=%g>%g',x3f,x3i,c,tol)

else
printf('\n

|%g-(%g)|=%g<%g',x3f,x3i,c,tol)

end
x1i=x1f
x2i=x2f
x3i=x3f
itera=itera+1
printf("\n\n%g ITERAO",itera)
x1f=((7-2*x2i-x3i)/10)
x2f=((-8-x1i-x3i)/5)
x3f=((6-2*x1i-3*x2i)/10)
printf('\n x1(%g)=%g',itera,x1f)
printf('\n x2(%g)=%g',itera,x2f)
printf('\n x3(%g)=%g',itera,x3f)
end
a=abs(x1f-x1i)
b=abs(x2f-x2i)
c=abs(x3f-x3i)
printf("\n

Critrio de parada")

printf('\n

|%g-(%g)|=%g<%g',x1f,x1i,a,tol)

printf('\n

|%g-(%g)|=%g<%g',x2f,x2i,b,tol)

printf('\n

|%g-(%g)|=%g<%g',x3f,x3i,c,tol)

Das könnte Ihnen auch gefallen