From 0efcb9d89dc584a7b7625c8b629664f634087713 Mon Sep 17 00:00:00 2001
From: "onica.klaudia" <onica.klaudia@hallgato.ppke.hu>
Date: Sat, 5 Jun 2021 23:09:59 +0200
Subject: [PATCH] Gradient descent method

---
 SIRC.m | 6 +++++-
 gd.m   | 7 +++++++
 2 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100644 gd.m

diff --git a/SIRC.m b/SIRC.m
index 494fa8d..6adb0ba 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 0000000..c5b1088
--- /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
-- 
GitLab