function Y = Linda
N=100; % Total size
en=50; % plot every nth time interval
T=zeros(N+1,N+1); % T is the transition matrix, defined below
v=linspace(0,N,N+1);
t(1)=1;
t=1;
beta=0.23;
v=20;
gamma=1;
b=11;
p=zeros(t(1)+1,N+1);
%p(1,3)=1; % Two individuals initially infected.
bt=beta*v.*(N-v)/N; dbstop if error
dt=(b+gamma)*v;
for i=1:N % Define the transition matrix
T(i,i)=1-bt(i)-dt(i); % diagonal entries
T(i,i+1)=dt(i+1); % superdiagonal entries
T(i+1,i)=bt(i); % subdiagonal entries
end
T(1,1)=1;
T(1,2)=dt(2);
T(N+1,N+1)=1-dt(N+1);
for t=1:t(1)
y=T*p(t,:);
p(t+1,:)=y;
end
pm(1,:)=p(1,:);
for t=1:t(1)/en;
pm(t+1,:)=p(en*t,:);
end
ti=linspace(0,t(1),t(1)/en+1);
st=linspace(0,N,N+1);
mesh(st,ti,pm);
xlabel('Number of Infectives');
ylabel('Time Steps');
zlabel('Probability');
view(140,30);
axis([0,N,0,time,0,1]);
%%%%%%%%%%%%%%%%%%%%%
%This is the error i'm having–
%Attempted to access dt(2); index out of bounds because numel(dt)=1.
Error in Linda (line 18)
T(i,i+1)=dt(i+1); % superdiagonal entries
Best Answer