solution

TYPE MATLAB CODE ANSWERING THE FOLLOWING:

function x = td(l, m, u, b)

% Solve a linear system Ax = b where A is tridiagonal
%
% Inputs: l, lower diagonal of A, n-1 by 1 vector
% m, main diagonal of A, n by 1 vector
% u, upper diagonal of A, n-1 by 1 vector
% b, right-hand constant in each equation, n by 1 vector
% Output: x, vector of unknowns, n by 1
%
%Example: if A = 2 -2 0 0
% -1 4 -2 0
% 0 -1 6 -2
% 0 0 -1 8
% and b = [24; 12; -98; 55],
% then l = [-1; -1; -1], m = [2; 4; 6; 8], u = [-2; -2; -2],
% and x = [10; -2; -15; 5]
%
%Another example: if n = 1E5; l = ones(n-1, 1); m = 3*ones(n, 1);
% u = ones(n-1, 1); b = ones(n, 1); b(1) = 0; b(n) = 0;
% x = td(l, m, u, b) will have x(1) = -0.10557

 
"Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!"
Looking for a Similar Assignment? Our Experts can help. Use the coupon code SAVE30 to get your first order at 30% off!

Hi there! Click one of our representatives below and we will get back to you as soon as possible.

Chat with us on WhatsApp