diff --git a/SIRC.m b/SIRC.m index 494fa8d188d1c1525fa00e174102852a59c82d3a..6adb0ba8d3b51195941e68eb71620821c3c7f7d1 100644 --- a/SIRC.m +++ b/SIRC.m @@ -206,4 +206,8 @@ plot(t, y_iv4); title('Instrumental variable method for the SIRC modell with additive Gaussian noise'); xlabel('Time(days)'); ylabel('Number of individuals'); -legend('S', 'I', 'R', 'C'); \ No newline at end of file +legend('S', 'I', 'R', 'C'); + +%% Gradient descent method +% For dCdt = gamma*q*I - (Gamma-mu)*C +theta_C = gd(X_C2, Y_C2, [gamma_lsq2*q_lsq2, Gamma_lsq2-mu_lsq2]', 0.01, 5); diff --git a/gd.m b/gd.m new file mode 100644 index 0000000000000000000000000000000000000000..c5b1088be900778da34fe6c6d3be1c8eef6b4f0b --- /dev/null +++ b/gd.m @@ -0,0 +1,7 @@ +function theta = gd(X, y, theta, alpha, num_iters) +m = length(y); +for iter = 1:num_iters + for i=1:size(X,2) + theta(i) = theta(i) - alpha/m * sum((X*theta - y).*X(:,i)); + end + end \ No newline at end of file