what is this error? and what is my mistake?
1 次查看(过去 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;|*
0 个评论
回答(1 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!