gauss method in matlab

6 vues (au cours des 30 derniers jours)
victor caixeta
victor caixeta le 6 Sep 2016
Hi all, i am making a code to solve a system of equations but i am geting the wrong result. function resolucao = resolve(A,B) a = det(A); if(a==0) fprintf('Sistema impossível ou com infinitas soluções.\n') else if A(1,1) == 0 A(2,2) == 0 A(2,2) == 0 A(3,3) == 0 fprintf('Método inválido para elementos na diagonal principal iguais a zero.\n') else for j = 3:-1:2 if A(j,1) == 0 B(j,1) = B(j,1); else B(j,1) = -A(1,1)/A(j,1)*B(j,1)+B(1,1) end if A(j,1)==0 for k=1:3 A(j,k)=A(j,k) end else for i = 1:3 A(j,i) = -A(1,1)*A(j,i)/A(j,1)+A(1,i) end end end for i2=2:3 if A(3,2) == 0 B(3,1) = B(3,1); else B(3,1) = -A(2,2)/A(3,2)*B(3,1) + B(2,1) end if A(3,2) == 0 A(3,i2) = A(3,i2); else A(3,i2) = -A(2,2)/A(3,2)*A(3,i2) + A(2,i2) end end x3 = B(3,1)/A(3,3) x2 = (B(2,1)-A(2,3)*x3)/A(2,2) x1 = (B(1,1)-A(1,2)*x2-A(1,3)*x3)/A(1,1) end end end
cheers!

Réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by