Skip to main content
added 89 characters in body
Source Link
Anjan Kumar
  • 5k
  • 1
  • 17
  • 29

If I understand it correctly, I think the following is what you want:

Solve the differential equation of n variables, with initial conditions defined using the previous differential equation solution of n-1 variables and with an initial condition for the last variable (which randomly depends on one of the previous variables).

The following code uses iniCond which generates initial conditions for a given i, diffGen generates equations with the initial conditions, and finally solveDiffGen solves the differential equations.

T = 50;
nu = 0.05;
vars[i_] := Subscript[x, #][t] & /@ Range[i];
iniCond[1] = {Subscript[x, 1][0] == 0.7};
diffGen[i_] := 
  Join[Table[{Subscript[x, j]'[t] == 
       Subscript[x, j][
         t] (1 - Subscript[x, j][t] - 
          nu (Sum[Subscript[x, k][t] Boole[k != j], {k, i}]))}, {j, 
      i}], iniCond[i]] // Flatten;
iniCond[i_] := 
  Module[{prevSolConds, lastCond}, 
   prevSolConds=prevSolConds = 
    NDSolve[diffGen[i - 1], 
       vars[[ivars[i - 1]]1], {t, 0, 
        T}] /. (x_ -> g_) :> {(x /. {t -> 0}) == (g /. {t -> T})} // 
     Flatten;
   lastCond = 
    Subscript[x, i][0] == 
      0.01 Subscript[x, RandomInteger[{1, i - 1}]][t] /. t -> T;
   {prevSolConds, lastCond} // Flatten
   ];Flatten];
solveDiffGen[i_] := NDSolve[diffGen[i], vars[[i]]vars[i], {t, 0, T}];

If I understand it correctly, I think the following is what you want:

Solve the differential equation of n variables, with initial conditions defined using the previous differential equation solution of n-1 variables and with an initial condition for the last variable (which randomly depends on one of the previous variables).

The following code uses iniCond which generates initial conditions for a given i, diffGen generates equations with the initial conditions, and finally solveDiffGen solves the differential equations.

iniCond[1] = {Subscript[x, 1][0] == 0.7};
diffGen[i_] := 
  Join[Table[{Subscript[x, j]'[t] == 
       Subscript[x, j][
         t] (1 - Subscript[x, j][t] - 
          nu (Sum[Subscript[x, k][t] Boole[k != j], {k, i}]))}, {j, 
      i}], iniCond[i]] // Flatten;
iniCond[i_] := Module[{prevSolConds, lastCond},
   prevSolConds= 
    NDSolve[diffGen[i - 1], 
       vars[[i - 1]], {t, 0, 
        T}] /. (x_ -> g_) :> {(x /. {t -> 0}) == (g /. {t -> T})} // 
     Flatten;
   lastCond = 
    Subscript[x, i][0] == 
      0.01 Subscript[x, RandomInteger[{1, i - 1}]][t] /. t -> T;
   {prevSolConds, lastCond} // Flatten
   ];
solveDiffGen[i_] := NDSolve[diffGen[i], vars[[i]], {t, 0, T}];

If I understand it correctly, I think the following is what you want:

Solve the differential equation of n variables, with initial conditions defined using the previous differential equation solution of n-1 variables and with an initial condition for the last variable (which randomly depends on one of the previous variables).

The following code uses iniCond which generates initial conditions for a given i, diffGen generates equations with the initial conditions, and finally solveDiffGen solves the differential equations.

T = 50;
nu = 0.05;
vars[i_] := Subscript[x, #][t] & /@ Range[i];
iniCond[1] = {Subscript[x, 1][0] == 0.7};
diffGen[i_] := 
  Join[Table[{Subscript[x, j]'[t] == 
       Subscript[x, j][
         t] (1 - Subscript[x, j][t] - 
          nu (Sum[Subscript[x, k][t] Boole[k != j], {k, i}]))}, {j, 
      i}], iniCond[i]] // Flatten;
iniCond[i_] := 
  Module[{prevSolConds, lastCond}, 
   prevSolConds = 
    NDSolve[diffGen[i - 1], 
       vars[i - 1], {t, 0, 
        T}] /. (x_ -> g_) :> {(x /. {t -> 0}) == (g /. {t -> T})} // 
     Flatten;
   lastCond = 
    Subscript[x, i][0] == 
      0.01 Subscript[x, RandomInteger[{1, i - 1}]][t] /. t -> T;
   {prevSolConds, lastCond} // Flatten];
solveDiffGen[i_] := NDSolve[diffGen[i], vars[i], {t, 0, T}];
added 8 characters in body
Source Link
Anjan Kumar
  • 5k
  • 1
  • 17
  • 29

If I understand it correctly, I think the following is what you want:

Solve the differential equation of n variables, with initial conditions defined using the previous differential equation solution of n-1 variables and with an initial condition for the last variable (which randomly depends on one of the previous variablevariables).

The following code uses iniCond which generates initial conditions for a given i, diffGen generates equations with the initial conditions, and finally solveDiffGen solves the differential equations.

iniCond[1] = {Subscript[x, 1][0] == 0.7};
diffGen[i_] := 
  Join[Table[{Subscript[x, j]'[t] == 
       Subscript[x, j][
         t] (1 - Subscript[x, j][t] - 
          nu (Sum[Subscript[x, k][t] Boole[k != j], {k, i}]))}, {j, 
      i}], iniCond[i]] // Flatten;
iniCond[i_] := Module[{prevSolConds, lastCond},
   prevSolConds= 
    NDSolve[diffGen[i - 1], 
       vars[[i - 1]], {t, 0, 
        T}] /. (x_ -> g_) :> {(x /. {t -> 0}) == (g /. {t -> T})} // 
     Flatten;
   lastCond = 
    Subscript[x, i][0] == 
      0.01 Subscript[x, RandomInteger[{1, i - 1}]][t] /. t -> T;
   {prevSolConds, lastCond} // Flatten
   ];
solveDiffGen[i_] := NDSolve[diffGen[i], vars[[i]], {t, 0, T}];

If I understand it correctly, I think the following is what you want:

Solve the differential equation of n variables, with initial conditions defined using the previous differential equation solution of n-1 variables and with an initial condition for the last variable (which randomly depends on the previous variable).

The following code uses iniCond which generates initial conditions for a given i, diffGen generates equations with the initial conditions, and finally solveDiffGen solves the differential equations.

iniCond[1] = {Subscript[x, 1][0] == 0.7};
diffGen[i_] := 
  Join[Table[{Subscript[x, j]'[t] == 
       Subscript[x, j][
         t] (1 - Subscript[x, j][t] - 
          nu (Sum[Subscript[x, k][t] Boole[k != j], {k, i}]))}, {j, 
      i}], iniCond[i]] // Flatten;
iniCond[i_] := Module[{prevSolConds, lastCond},
   prevSolConds= 
    NDSolve[diffGen[i - 1], 
       vars[[i - 1]], {t, 0, 
        T}] /. (x_ -> g_) :> {(x /. {t -> 0}) == (g /. {t -> T})} // 
     Flatten;
   lastCond = 
    Subscript[x, i][0] == 
      0.01 Subscript[x, RandomInteger[{1, i - 1}]][t] /. t -> T;
   {prevSolConds, lastCond} // Flatten
   ];
solveDiffGen[i_] := NDSolve[diffGen[i], vars[[i]], {t, 0, T}];

If I understand it correctly, I think the following is what you want:

Solve the differential equation of n variables, with initial conditions defined using the previous differential equation solution of n-1 variables and with an initial condition for the last variable (which randomly depends on one of the previous variables).

The following code uses iniCond which generates initial conditions for a given i, diffGen generates equations with the initial conditions, and finally solveDiffGen solves the differential equations.

iniCond[1] = {Subscript[x, 1][0] == 0.7};
diffGen[i_] := 
  Join[Table[{Subscript[x, j]'[t] == 
       Subscript[x, j][
         t] (1 - Subscript[x, j][t] - 
          nu (Sum[Subscript[x, k][t] Boole[k != j], {k, i}]))}, {j, 
      i}], iniCond[i]] // Flatten;
iniCond[i_] := Module[{prevSolConds, lastCond},
   prevSolConds= 
    NDSolve[diffGen[i - 1], 
       vars[[i - 1]], {t, 0, 
        T}] /. (x_ -> g_) :> {(x /. {t -> 0}) == (g /. {t -> T})} // 
     Flatten;
   lastCond = 
    Subscript[x, i][0] == 
      0.01 Subscript[x, RandomInteger[{1, i - 1}]][t] /. t -> T;
   {prevSolConds, lastCond} // Flatten
   ];
solveDiffGen[i_] := NDSolve[diffGen[i], vars[[i]], {t, 0, T}];
added 11 characters in body
Source Link
Anjan Kumar
  • 5k
  • 1
  • 17
  • 29

If I understand it correctly, I think the following is what you want:

Solve the differential equation of n variables, with initial conditions defined using the previous differential equation solution of n-1 variables and with an initial condition for the last variable (which randomly depends on the previous variable).

The following code uses iniCond which generates initial conditions for a given i, diffGen generates equations with the initial conditions, and finally solveDiffGen solves the differential equations.

iniCond[1] = {Subscript[x, 1][0] == 0.7};
diffGen[i_] := 
  Join[Table[{Subscript[x, j]'[t] == 
       Subscript[x, j][
         t] (1 - Subscript[x, j][t] - 
          nu (Sum[Subscript[x, k][t] Boole[k != j], {k, i}]))}, {j, 
      i}], iniCond[i]] // Flatten;
iniCond[i_] := Module[{conditionsprevSolConds, lastCond},
   conditions =prevSolConds= 
    NDSolve[diffGen[i - 1], 
       vars[[i - 1]], {t, 0, 
        T}] /. (x_ -> g_) :> {(x /. {t -> 0}) ->== (g /. {t -> T})} // 
     Flatten;
   {conditionslastCond /.= 
      Rule -> Equal, {Subscript[x, i][0] == 
        0.01 Subscript[x, RandomInteger[{1, i - 1}]][t] /. t -> T}} //T;
   {prevSolConds, lastCond} // Flatten
   ];
solveDiffGen[i_] := NDSolve[diffGen[i], vars[[i]], {t, 0, T}];

If I understand it correctly, I think the following is what you want:

Solve the differential equation of n variables, with initial conditions defined using the previous differential equation solution of n-1 variables and with an initial condition for the last variable (which randomly depends on the previous variable).

The following code uses iniCond which generates initial conditions for a given i, diffGen generates equations with the initial conditions, and finally solveDiffGen solves the differential equations.

iniCond[1] = {Subscript[x, 1][0] == 0.7};
diffGen[i_] := 
  Join[Table[{Subscript[x, j]'[t] == 
       Subscript[x, j][
         t] (1 - Subscript[x, j][t] - 
          nu (Sum[Subscript[x, k][t] Boole[k != j], {k, i}]))}, {j, 
      i}], iniCond[i]] // Flatten;
iniCond[i_] := Module[{conditions},
   conditions = 
    NDSolve[diffGen[i - 1], 
       vars[[i - 1]], {t, 0, 
        T}] /. (x_ -> g_) :> {(x /. {t -> 0}) -> (g /. {t -> T})} // 
     Flatten;
   {conditions /. 
      Rule -> Equal, {Subscript[x, i][0] == 
        0.01 Subscript[x, RandomInteger[{1, i - 1}]][t] /. t -> T}} //
     Flatten
   ];
solveDiffGen[i_] := NDSolve[diffGen[i], vars[[i]], {t, 0, T}];

If I understand it correctly, I think the following is what you want:

Solve the differential equation of n variables, with initial conditions defined using the previous differential equation solution of n-1 variables and with an initial condition for the last variable (which randomly depends on the previous variable).

The following code uses iniCond which generates initial conditions for a given i, diffGen generates equations with the initial conditions, and finally solveDiffGen solves the differential equations.

iniCond[1] = {Subscript[x, 1][0] == 0.7};
diffGen[i_] := 
  Join[Table[{Subscript[x, j]'[t] == 
       Subscript[x, j][
         t] (1 - Subscript[x, j][t] - 
          nu (Sum[Subscript[x, k][t] Boole[k != j], {k, i}]))}, {j, 
      i}], iniCond[i]] // Flatten;
iniCond[i_] := Module[{prevSolConds, lastCond},
   prevSolConds= 
    NDSolve[diffGen[i - 1], 
       vars[[i - 1]], {t, 0, 
        T}] /. (x_ -> g_) :> {(x /. {t -> 0}) == (g /. {t -> T})} // 
     Flatten;
   lastCond = 
    Subscript[x, i][0] == 
      0.01 Subscript[x, RandomInteger[{1, i - 1}]][t] /. t -> T;
   {prevSolConds, lastCond} // Flatten
   ];
solveDiffGen[i_] := NDSolve[diffGen[i], vars[[i]], {t, 0, T}];
Source Link
Anjan Kumar
  • 5k
  • 1
  • 17
  • 29
Loading