Borrar filtros
Borrar filtros

what is this error? and what is my mistake?

1 visualización (últimos 30 días)
DJ
DJ el 30 de Mayo de 2013
I want to make Gauss Seidel Relaxation matlab code.
there is my script. and i dont know what is problem..
plz answer.. to make an right script.
function [x,ea,iter]=GaussSeidelR(A,b,lamda,es,maxit)
% GaussSeidel: Gauss Seidel Method
% x=GaussSeidel(A,b): Gauss Seidel without relaxation % input:
% A= coefficient matrix % b=right hand side vector % es=stop criterion (default=0.00001%) % maxit=max iteration (default = 50)
% output:
% x=solution vector
if nargin<2, error('at least 2 input arguments requried'),end if nargin<5 | isempty(maxit), maxit=50; end if nargin<4 | isempty(es), es=0.00001; end if nargin<3 | isempty(lamda), lamda=1; end
[m,n]=size(A); if m~=n, error('Matrix A must be square'); end C=A; for i=1:n C(i,i)=0; x(i)=0; end x=x'; for i=1:n C(i,1:n)=C(i,1:n)/A(i,i); end for i=1:n d(i)=b(i)/A(i,i); end iter=0; while(1)
xold=x;
for i=1:n
x(i)=d(i)-C(i,:)*x;
x(i)=lamda*x(i)+(1-lamda)*xold;
if x(i)~=0
ea(i)=abs((x(i)-xold(i))/x(i))*100;
end
end
iter=iter+1;
if max(ea)<=es | iter>=maxit, break, end
end
*|error massage
>> [x,ea,iter]=GaussSeidelR(A,b,lamda) ??? In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in ==> GaussSeidelR at 38 x(i)=lamda*x(i)+(1-lamda)*xold;|*

Respuestas (1)

Iain
Iain el 30 de Mayo de 2013
The error is that you are trying to put more than ONE element into a single element of an array.
Either change x(i) to x(i,:) or x(:,i), OR ensure that lambda is a scalar value.

Categorías

Más información sobre Operating on Diagonal Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by