% Class 15 - More on linear sys of eqns.
% Coded by NFR on 10.15.19
%
% Review banded matrix (tridiag)
% with diffusion problem
% see paper for setup of A matrix
%
e = ones(8,1)*5; % Sub diagonal
f = ones(9,1)*-8.4; % diagonal
g = ones(8,1)*3; % super diagonal
r = zeros(9,1);
r(1,1) = -5*80; r(9,1) = -30;
% Call tridiag to solve this problem
c_int = tridiag(e,f,g,r);
% Plot all points, must add the first and last
c_all = [80 c_int' 10];
x_vec = 0:10;
plot(x_vec,c_all,'r.','MarkerSize',20)
% Stimulus Response Problems
%
A = [225 0 -25 0;
0 175 0 -125;
-225 0 275 -50;
0 -25 -250 275];
b = [1400; 100; 2000; 0];
c_vec = A\b
% Asking a question that
% uses the inverse matrix
% Answer question about
% fixed grill and no smoking
AI = inv(A);
DropLevel = AI(2,1)*1000+AI(2,3)*2000;
NewLevel_Room2 = c_vec(2)-DropLevel
% Double check by resolving the sys of equations
b_new = [400; 100; 0; 0];
c_new = A\b_new;
c_new(2)
% Another example of a stimuls response problem
% 11.3 from the book
A = [15 -3 -1;
-3 18 -6;
-4 -1 12];
b = [4000 1500 2400]';
AI = inv(A)
cvec = AI*b
% Part c, response is in reactor 1
% stimulus is coming from reactor 3
% so we will use AI(1,3) as the coefficient
% that links this stimulus to this response
%
% 10 = AI(1,3)*Stimulus
Stim_Reac3 = 10/AI(1,3)
% Check this answer by re-solving the balance
b_vec = [4000 1500 2400+Stim_Reac3]';
cnew = AI*b_vec; % resolve
cnew(1,1)-cvec(1,1)
% Part d
% Response is in reactor 3 (ROW)
% Stimuli are in 1 and 2 (Columns)
% Coeff= AI(3,1) and AI(3,2)
Reac3_INC = AI(3,1)*500 +AI(3,2)*250