Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

function y - tridiag( a, b, c, f ) % Solve the n x n tridiagonal system for y: b

ID: 3167894 • Letter: F

Question

function y - tridiag( a, b, c, f ) % Solve the n x n tridiagonal system for y: b (2) a(2) c (2) 1 Y(2)£ (2) b(3) a (3) c(3) b (n-1) a(n-1) c (n-1) y(n-1) ] [ f(n-1) ] b (n) a (n) Y(n) £(n) f must be a vector (row or column) of length n % a, b, c must be vectors of length n (note that b(1) and c (n) are not used) % some additional information is at the end of the file n = length ( f ) ; v = zeros ( n, 1) ; w = a(1); for i-2:n v(i-1) -c(i-1)/wi w = a(i) -b(i)ty(1-1 ) ; end for j-n-1:-1:1 yj) y(j) - v(j)*y(j+1); end

Explanation / Answer

function y=Thomas_alg(a,b,c,f)

n=length(f);

b1(1)=b(1);
f1(1)=f(1);

for i=1:n
   c1(i)=c(i);
end

for i=2:n
   b1(i)=b(i)-(c1(i-1)*(a(i)/b1(i-1)));
end

for i=2:n
   f1(i)=f(i)-(f1(i-1)*(a(i)/b1(i-1)));
end

y(n)=f1(n)/b1(n);

for i=n-1:-1:1
y(i)=(f1(i)-c1(i)*u(i+1))/b1(i);
end

end