# MATLAB: Unable to perform assignment because the left and right sides have a different number of elements.

euler

%% Euler framÃ¥t
clc
clear all
close all
%parametrar (samma som ovan)
tMax = 20;
timeSpan = [0 tMax];
S0 = 1.0;
I0 = 0.0;
R0 = 0.0;
dt = 0.01;
time_vector = 0:dt:tMax;
nIterations = length(time_vector);
tau = 0.6;
h = 0.5;
rho = 0.8;
r = 0.2;
beta = (h*exp(-h*tau))/(1-exp(-h*tau));
%Euler
S = zeros(size(time_vector));
I = zeros(size(time_vector));
R = zeros(size(time_vector));
S(1) = S0;
I(1) = I0;
R(1) = R0;
%vi utnyttjar att: nIterations = length(time_vector) = numel(S)
for i=1:nIterations-1
S(i+1)= S(i)-dt.*(h.*S+rho.*I+beta.*R);
I(i+1)= I(i)+dt.*(h.*S-rho.*I-r.*I);
R(i+1)= R(i)+dt.*(r.*I-beta.*R);
end
%plotta euler framÃ¥t
figure(2)
plot(0:tMax,S)
hold on
plot(0:tMax,I)
hold on
plot(0:tMax,R)

``for i=1:nIterations-1    S(i+1)= S(i)-dt.*(h.*S(i)+rho.*I(i)+beta.*R(i));    I(i+1)= I(i)+dt.*(h.*S(i)-rho.*I(i)-r.*I(i));    R(i+1)= R(i)+dt.*(r.*I(i)-beta.*R(i));end``
``%plotta euler framÃ¥tt = linspace(0, tMax, numel(S));figure(2)plot(t,S)hold on plot(t,I)plot(t,R)  hold offgridlegend('S(t)','I(t)','R(t)')``