Help with MATLAB!!!

edited July 2008 in Science & Tech
Hi! I have just started learning how to use MATLAB and I have been trying to solve this problem now for a while but keep coming up with errors :sad2:. I hope someone can help me out with this.
Basically we were asked to write a function in MATLAB for Jacobi Method and the function I wrote is as follows:

function x = jacobi(A,b,y,N)
% This function applies N iterations of Jacobi's method
% to the system of linear equations Ax=b
n = length(y);
for k=1:N
for i=1:n
sum=b(i);
for j=1:i-1
sum = sum - A(i,j)*y(j);
end
for j = i+1:n
sum = sum - A(i,j)*y(j);
end
x(i) = sum/A(i,i);
end
y = x';
end

Today in class we were asked to perform 5 iterations with A=[4,1,-1;-1,3,1;2,2,5], b=[5;-4;1] and an inital estimate of x(0)= [4,2,1]^T. So I wrote the following script file to do this but I keep coming up the error:
A=input(
'Enter a matrix ');
b=input('Enter a vector ');
x=input('Enter initial estimate ');
n=input('Enter number of iterations ');
for i=1:n
x=jacobi(A,b,y);
disp(x)
end

The following error keeps on coming up everytime I run the script file:confused::
??? Input argument "N" is undefined.
Error in ==> jacobi at 5
for k=1:N
Error in ==> tut2q1trial at 6
x=jacobi(A,b,y);

HELP PLEASE!!:)
Sign In or Register to comment.