Hi this error is being generated:
In an assignment A(:) = B, the number of elements in A and B must be the same.Error in q1_gs_150115 (line 42) x(k) = num/At(k,k);
My code :
function [GS] = q1_gs_150115(~)m=input('variables');r=input('relaxation_number');for i=1:mfor j=1:mA(i,j)=input('element_i,j');endendA=reshape(A,m,m);for i = 1:mj = 1:m; j(i) = []; B = abs(A(i,j)); c(i) = abs(A(i,i)) - sum(B); % Is the diagonal value greater than the remaining row values combined?
if c(i) > 0 fprintf('The matrix is diagonally dominant at row %2i\n\n',i) endendfor i=1:ms(i,1)=input('constants_i');endp=input('number_of_iterations');for i=1:mx(i,1)=input('initial_values_i');enderr = zeros(m,1);At = [A,s];for iter = 1:p for k = 1:m xold = x(k); num = (1-r)*At(k,k)*x(k+1:m)+ r*At(k,end) - r*At(k,1:k-1)*x(1:k-1) - r*At(k,k+1:m)*x(k+1:m); x(k) = r*num/At(k,k); err(k) = abs(x(k)-xold); end disp(['Iter ',num2str(iter), '; Error =', num2str(max(err))]); end disp('The result is:')disp(x)
Best Answer