Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // O METODO D ESCALONAMENTO NÃO FUNCIONA DE MANEIRA OTIMA, É SIMPLISTICO !
- function mPronta = escalonamento(m, L)
- for(i = 1:L)
- for(j = (i+1):L)
- if(m(i,i) ~= 0)
- c = ( m(j,i)/m(i,i) ) * (-1);
- m(j,:) = m(j,:) + m(i,:) * c;
- end
- end;
- end;
- mPronta = m;
- endfunction
- function s = gauss(m, L, C)
- s = zeros(L,1);
- for(i = L:-1:1)
- s(i) = m(i,C);
- for(j = i+1:L)
- s(i) = s(i) - m(i,j) * s(j);
- end
- s(i)= s(i)/m(i,i);
- end
- endfunction
- // leitura
- m = [ 1 -3 2; -2 8 -1; 4 -6 5];
- r = [ 11; -15; 29];
- m(:, $+1) = r;
- // escalonando
- tam = size(m);
- m = escalonamento(m,tam(1,1)); // passando o numero de linhas em tam(1,1)
- disp(m);
- // gauss
- coef = gauss(m, tam(1,1), tam(1,2) );
- // valores de X0 ate Xn-1
- disp(coef);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement