Here is my matlab code for the matrix

function [a] = bandedsetup(n) % Gives name to mfile to call in cmd window

e = ones(n,1); % Creates a column vector with n values = 1

e = 3*e; % Creates a column vector with n values = 3

a = spdiags([e/3 -e-1 2*e -e-1 e/3], -2:2,n,n); % Entries of matrix a using spdiags function. Here the

% numbers 1,-4,6,-4,1 that move down the diagonal begins at -2 on the first

% row of the matrix so that on row 2, the value -4 appears in the first

% column, and that in row 3, the value 1 appears in the first column, ect..

% The following lines of code change certain values of the matrix a to give

% the matrix presented in the question

a(1,1) = 12;

a(1,2) = -6;

a(1,3) = 4/3;

a(10,8) = 4/3;

a(10,9) = -6;

a(10,10) = -12;

Here is my code for the rhs

function [rhs, fvector, coeffrhs] = bvector(n)

L = 10; % L is length of the beam(in metres)

w = 0.1; % w is the width of the beam (in metres)

depth = 0.05; % Defines the depth of the beam (in metres)

d = 7850; % Defines the density of steel (in kg/m^2)

g=9.81; % Defines the gravitational constant (m/sec^2)

E = 2*(10^11); % Young's modulus of steel (Newton/m^2)

h = L/(n); % h as defined in the problem

I = (w*(h^3))/12; % I defines the area moment of inertia

f = d*w*depth*g;

b=zeros(n,1);

for i =1:n % Determines the applied load for each value of x

b(i,1) = f; % Weight of the beam loop

end% Ends the loop

fvector = b;

coeffrhs= (h^4)/(E*I);

rhs= fvector*coeffrhs;

Here is my code for the Jacobi method

unction x = jacobi(k) % Gives name to mfile to call in cmd window

a = bandedsetup(10); % Defines a to be answer produced by bandedsetup

rhs = bvector(10); % Defines b to be the answer produced by bvector.m

n = length(rhs); % Defines n to be the length of vector b

d = diag(a); % Extracts diagonal values in a

r = a - diag(d); % Produces the remainder

x = zeros(n,1); % Creates a column vector,x, of length n with values of zero

for j = 1:k % Beginning of Jacobi method loop

x = (rhs-r*x)./d; % Defines x for each k

end% Ends Jacobi method loop

Now when I run jacobi(k), at say k=100,000 or something like that I keep getting the values of y_i = (NaN)...........................im not sure how to fix this?

Can anyone help me?

Thanks in advance to anyone who can.