Question:

Help with Matlab!!?

by Guest31877  |  earlier

0 LIKES UnLike

I have just started learning how to use MATLAB&I have been tryn to solve this problem now for a while but keep coming up with errors. We were asked to write a function in MATLAB for Jacobi Method&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]&an inital estimate of x(0)= [4,2,1]^T. 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

Error:

??? Input argument "N" is undefined.

Error in ==>jacobi at 5

 Tags:

   Report

1 ANSWERS


  1. Your function declares:

    function x = jacobi(A,b,y,N)

    When you call it you use:

    x=jacobi(A,b,y);

    You are not providing the N input in the function call. needed for you K loop. You need to define N and then pass it in your call:

    N=??;

    x=jacobi(A,b,y,N);

You're reading: Help with Matlab!!?

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions