# Linear System Theory Assignment2
###### tags: `Linear System Theory` `assignment2`
* Consider a large population of N individuals, and a disease in which infection spreads by contact between individuals.
* Individuals who are once infected either
* (i) recover and are immune, or
* (ii) die or isolated.
* any one time the popu- lation is comprised of
* x1 susceptible individuals,
* x2 infected and circulating individuals, and
* x3 individuals who are either immune or die.
### x1+x2+x3 = N
* the rate of contact between those who are susceptible and those who are infective is proportional to the product $x1\times x2$.
* The rate of generation of new infections is $β\times x1 \times x2$, **where β > 0 is an infection-rate constant**.
* Infective individualss are assumed to be removed or become immune at a rate propor- tional to their number with **an associated removal constant γ > 0**.
* Let x10, x20, x30 be the initial values of x1, x2, x3 at t = t0.
* by adding the three variables one sees that
* d(x1 + x2 + x3)/dt = 0, which implies that x1(t)+x2(t)+x3(t) is a constant
* and equals x10 +x20 +x30 = 1.
* Let β = 1/3, γ = 1/15, and t0 = 0
```matlab=
clear, clc
format long;
h=0.5;
delta = 0.05; % step size, delta = 0.05
t = 0:delta:60; % Calculates upto t in (0; 60)
beta = 1/3;
gamma = 1/15;
f=@(t,y) [-beta*y(1)*y(2), beta*y(1)*y(2)-gamma*y(2), gamma*y(2)];
[x,y]=runge_kutta_4(f,[0,60],[0.8, 0.1, 0.1], 0.005);
plot(x,y);
title('When Time Step is 0.005');
legend('x_1(t)', 'x_2(t)', 'x_3(t)', 'Location', 'NorthEast')
xlabel('t')
ylabel('Solutions')
figure;
hold on;
function [x,y]=runge_kutta_4(f,tspan,y0,h)
x = tspan(1):h:tspan(2); % Calculates upto y(3)
y = zeros(length(x),3);
y(1,:) = y0; % Initial Conditions
for i=1:(length(x)-1)
k_1 = f(x(i),y(i,:));
k_2 = f(x(i)+0.5*h,y(i,:)+0.5*h*k_1);
k_3 = f((x(i)+0.5*h),(y(i,:)+0.5*h*k_2));
k_4 = f((x(i)+h),(y(i,:)+k_3*h));
y(i+1,:) = y(i,:) + (1/6)*(k_1+2*k_2+2*k_3+k_4)*h;
end
end
```
~~~
check the note on 2/24 office hour, differential equations, ... e.t.c
~~~
> [Matrix of function example, MATLAB](https://www.mathworks.com/matlabcentral/answers/324720-how-to-perform-operations-using-matrix-of-functions)
>[Create Symbolic Functions with Matrices as Formulas](https://www.mathworks.com/help/symbolic/syms.html#:~:text=For%20brevity%2C%20an%20array%20of,in%20the%20MATLAB%C2%AE%20workspace.)
$\begin{bmatrix}
1/3*x_2 & -1/3*x_1 & 0 \\
1/3*x_2-1/15x_2 & 1/3*x_1-1/15 & 0 \\
0 & 0 & 0 \\
\end{bmatrix} = A(x)$