Jacobi method giving an error

조회 수: 2 (최근 30일)
Isaac Al-rai
Isaac Al-rai 2018년 2월 17일
댓글: Image Analyst 2018년 2월 17일
For a numerical methods class I am in I have to create a function that solve an arbitrarily system of linear equations using the jacobi method. I am testing out a code from my textbook
%
function X=jacobi(A,B,P,delta,max1)
N = length(B);
if true
% code
end
for k=1:max1
for j=1:N
X(j)=(B(j)-A(j,[1:j-1,j+1:N])*P([1:j-1,j+1:N]))/A(j,j);
end
err=abs(norm(X'-P));
relerr=err/(norm(X)+eps);
P=X';
if (err<delta)||(relerr<delta)
break
end
end
if true
% code
end
X=X';
end
end
Where delta is my tolerance and max1 is number of iterations.
And when I enter it (after defining my A,B, and P terms) I am giving the following error:
if true
% code
X=@jacobi(A,b,P,0.001,1);
X=@jacobi(A,b,P,0.001,1);
Error: Unbalanced or unexpected parenthesis or bracket.
end
What does this mean? Dont I need to put the function in parenthesis in order for it to run?

채택된 답변

Image Analyst
Image Analyst 2018년 2월 17일
Get rid of the @ symbol. Just call it by it's name alone.
X = jacobi(A,b,P,0.001,1);
  댓글 수: 3
Isaac Al-rai
Isaac Al-rai 2018년 2월 17일
Thought I might ask this too, is there a way I can make this function run using only one for loop?
Image Analyst
Image Analyst 2018년 2월 17일
Looks like you might be able to do it with conv() or conv2(), but I've not gotten into the details to figure it out. Maybe you can.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by