gauss method in matlab

조회 수: 14 (최근 30일)
victor caixeta
victor caixeta 2016년 9월 6일
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!

답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by