Created
December 2, 2023 21:31
-
-
Save SheriKabashi/00ab9bbda4cb0f2650359474272628d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include "ode_def.h" | |
| #include <cpgplot.h> | |
| #include <cmath> | |
| using namespace std; | |
| double dTdt(double b, double Tt, double Vt) { | |
| return -b * Tt * Vt; | |
| } | |
| double dIdt(double b, double s, double Tt, double Vt, double It) { | |
| return b * Tt * Vt - s * It; | |
| } | |
| double dVdt(double p, double c, double Vt, double It) { | |
| return p * It - c * Vt; | |
| } | |
| int main() { | |
| int n = 7000; | |
| double tstart = 0, tend = 7, deltaT = 0.001; | |
| //Parameters | |
| double b = 3.4*pow(10,-4.54), s = 3.4, p = 7.9e-3, c = 3.3; | |
| //Initial Values | |
| double T0 = 4 * std::pow(10, 8), I0 = 0.0001, V0 = 0.35; | |
| double t = tstart, Tt = T0, It = I0, Vt = V0; | |
| float tp[n + 1]; | |
| float Tp[n + 1]; | |
| float Ip[n + 1]; | |
| float Vp[n + 1]; | |
| tp[0] = tstart; | |
| Tp[0] = T0; | |
| Ip[0] = I0; | |
| Vp[0] = V0; | |
| for (int i = 0; i <= n; i++) { | |
| t += deltaT; | |
| Tt += deltaT * dTdt(b, Tt, Vt); | |
| It += deltaT * dIdt(b, s, Tt, Vt, It); | |
| Vt += deltaT * dVdt(p, c, Vt, It); | |
| tp[i + 1] = t; | |
| Tp[i + 1] = Tt; | |
| Ip[i + 1] = It; | |
| Vp[i + 1] = Vt; | |
| } | |
| if (!cpgopen("/XWINDOW")) return 1; | |
| cpgenv(tstart, tend, 1e-5, 4e8, 0, 0); | |
| cpglab("Time (days)", "Population", "Influenza A Model"); | |
| //dTdt | |
| cpgsci(13); //Pink | |
| cpgline(n + 1, tp, Tp); | |
| //dIdt | |
| cpgsci(2); //Red | |
| cpgline(n + 1, tp, Ip); | |
| //dVdt | |
| cpgsci(3); //Green | |
| cpgline(n + 1, tp, Vp); | |
| cpgtext(tstart + 4, 3.5e8, "dT/dt (Pink)"); | |
| cpgtext(tstart + 4, 3e8, "dI/dt (Red)"); | |
| cpgtext(tstart + 4, 2.5e8, "dV/dt (Green)"); | |
| cpgend(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment