0
$\begingroup$
TH = 400;
S =500;
\[Mu]e = 60;
\[Mu]g = 30;
\[Lambda]e = 150;
(*variable*)
p[i_, j_] := Subscript[p, i, j] /; j == 0 && i == S
p[i_, j_] := Subscript[p, i, j] /; j == 0 && TH < i && i < S
p[i_, j_] := Subscript[p, i, j] /; j == 0 && i == TH
p[i_, j_] := Subscript[p, i, j] /; j == S - i && S - TH <= i && i < S
p[i_, j_] := Subscript[p, i, j] /; j == TH - i && 0 < i && i < TH
p[i_, j_] := Subscript[p, i, j] /; j == TH && i == 0
p[i_, j_] := Subscript[p, i, j] /; j == TH && 0 < i && i < S - TH
p[i_, j_] := Subscript[p, i, j] /;  0 < j && j < TH && (TH - j) < i && i < (S - j)
p[i_, j_] := 0
k = Table[p[i, j], {i, 0, S}, {j, 0, TH}] // Flatten;
m = DeleteCases[k, 0];
o = Total[m];
(*Simultaneous equations*)
Clear[sosa]
sosa[i_, j_] := \[Mu]e*Subscript[p, i, j] == \[Lambda]e* Subscript[p, i - 1, j] /; j == 0 && i == S(*No1*)
sosa[i_, j_] := (\[Lambda]e + \[Mu]e)* Subscript[p, i, j] == \[Mu]e*Subscript[p, i + 1, j] + \[Mu]g* Subscript[p, i, j + 1] + \[Lambda]e*Subscript[p, i - 1, j] /;  j == 0 && TH < i && i < S(*No2*)  
sosa[i_, j_] := (\[Lambda]e + \[Mu]e)* Subscript[p, i, j] == \[Mu]e*Subscript[p, i + 1, j] + \[Mu]g* Subscript[p, i, j + 1] /; j == 0 && i == TH(*No3*)
sosa[i_, j_] := (\[Mu]e + \[Mu]g)*Subscript[p, i, j] == \[Lambda]e* Subscript[p, i - 1, j] /; j == S - i && S - TH <= i && i < S(*No4*)
sosa[i_, j_] := (\[Lambda]e + \[Mu]e)* Subscript[p, i, j] == \[Mu]e*Subscript[p, i + 1, j - 1] + \[Mu]e* Subscript[p, i + 1, j] + \[Mu]g*Subscript[p, i, j + 1] /;  j == TH - i && 0 < i && i < TH(*No5*)
sosa[i_, j_] := \[Lambda]e* Subscript[p, i, j] == \[Mu]e*Subscript[p, i + 1, j - 1] + \[Mu]e* Subscript[p, i + 1, j] /; j == TH && i == 0(*No6*)
sosa[i_, j_] := (\[Lambda]e + \[Mu]e + \[Mu]g)* Subscript[p, i, j] == \[Mu]e*Subscript[p, i + 1, j] + \[Lambda]e* Subscript[p, i - 1, j] /; j == TH && 0 < i && i < S - TH(*No7*)
sosa[i_, j_] := (\[Lambda]e + \[Mu]e + \[Mu]g)* Subscript[p, i, j] == \[Mu]e*Subscript[p, i + 1, j] + \[Lambda]e* Subscript[p, i - 1, j] + \[Mu]g*Subscript[p, i, j + 1] /;  0 < j && j < TH && (TH - j) < i && i < (S - j)(*No8*) 
sosa[i_, j_] := 0
sosalist1 = Table[sosa[i, j], {i, 0, S}, {j, 0, TH}] // Flatten;
eqns = DeleteCases[sosalist1, 0];
seikikasiki = {o == 1};
sosasiki = Join[eqns, seikikasiki] // Flatten;
ans = NSolve[sosasiki, m] // Flatten
general = Plus @@ Table[p[i, TH - i], {i, 0, TH}];
emergency = Plus @@ Table[p[i, S - i], {i, 0, S}];
gen=general /. ans
eme=emergency /. ans
Export["call.csv",ans]
Export["gen.csv",gen]
Export["eme.csv",eme]

In this program, I would like to solve by changing the threshold value TH with S = 500. However, the calculation stops midway. I don't know if the cause is memory or underflow. Anything is fine, so I would like to ask if you have any advice. Thank you.

$\endgroup$
  • 1
    $\begingroup$ These equations appear to be linear so that it should be much more efficient in terms of time and memory to formulate them as a linear system with a SparseArray as system matrix and to solve them with LinearSolve. $\endgroup$ – Henrik Schumacher May 3 at 9:39
  • $\begingroup$ @Henrik Schumacher Thank you for the advice. I'll try! $\endgroup$ – Kenta Kawai May 7 at 2:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.