필터 지우기
필터 지우기

what is this error? and what is my mistake?

조회 수: 1 (최근 30일)
DJ
DJ 2013년 5월 30일
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;|*

답변 (1개)

Iain
Iain 2013년 5월 30일
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.

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by