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

Needs to be done in Matlab script. A tri-diagonal system is one where the coeffi

ID: 2325918 • Letter: N

Question

Needs to be done in Matlab script.

A tri-diagonal system is one where the coefficient matrix is banded on either side of the diagonal. One way to represent the system of equations is by representing the coefficient matrix by three vectors, the sub-diagonal {e}, the diagonal {f} and the super-diagonal {g}. Vectors {e} and {g} will be length n-1 while vector {f} will be length n. Let {b} be the right hand side vector. Construct a function called Tridiag following the flow diagram shown below to solve for this special, yet common, case. In your script, use the function to solve the following set of equations: [2.01 3 0 0 -1 2.01 3 0 0 -1 2.01 3 0 0 -1 2.01] {T_1 T_2 T_3 T_4} = {50 0 0 -1020}

Explanation / Answer

Following Code is for MATLAB.

Define following code in Tridiag.m file

function x=Tridiag(e,f,g,b)

n=length(f);
x=zeros(1,n);
k=2;

while k<=n
factor=e(k-1)/f(k-1);
f(k)=f(k)-factor*g(k-1);
b(k)=b(k)-factor*b(k-1);
k=k+1;
end

x(n)=b(n)/f(n);
i=n-1;

while i>0
x(i)=(b(i)-g(i)*x(i+1))/f(i);
i=i-1;
end

disp('Values of X is')
disp(' ')
disp(x)

end

Now to use this function define e,f,g and b vectors in different script file as below:

clc
close all
clear all

e=[-1 -1 -1];
f=[2.01 2.01 2.01 2.01];
g=[3 3 3];
b=[50 0 0 -1020];

x=Tridiag(e,f,g,b);

Make sure to save both the files in same location in order to run the script.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote