How can I convert "reprperf" and "reprimperf" to lists or vectors so that I can use the command ListPlot[startsol, reprperf, reprimperf] to compare the three?
Clear["Global`*"]
Clear[n]
Clear[L]
Clear[H]
udist = UniformDistribution[{0, H}];
updfdist = PDF[udist, t];
ucdfdist = CDF[udist, t];
(n = 4;
xvec = Table[Subscript[x, i], {i, 1, n + 1}];
xvec // MatrixForm
Clear[\[Psi]vec];
\[Psi]vec = Table[0, {i, 1, n + 2}];
\[Psi]vec[[1]] = CDF[udist, Subscript[x, 1]];
For[i = 2, i <= n + 1,
i++, \[Psi]vec[[i]] =
Assuming[{Subscript[x, i] > Subscript[x, i - 1],
Subscript[x, i] < H},
CDF[udist, Subscript[x, i]] - CDF[udist, Subscript[x, i - 1]]]];
\[Psi]vec[[n + 2]] = 1 - CDF[udist, Subscript[x, n + 1]];
\[Psi]vecc = Transpose[\[Psi]vec, {1}];)
(n = 4;
\[Alpha] = 0.4;
\[Beta] = 0.1;
cR = 1000.;
Co = 10000.;
Cs = 2500.;
Ci = 400.;
cF = 200.;
H = 200;
\[Lambda]vec = Table[0, {i, 1, n + 2}];
\[Lambda]vec[[1]] = Ci (1 - \[Beta]) \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(k = 1\), \(n\)]\(k\
\*SuperscriptBox[\(\[Beta]\), \(k - 1\)]\)\) + Ci n \[Beta]^n;
For[i = 2, i <= n, i++, \[Lambda]vec[[i]] = Ci \[Alpha] \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(k = 1\), \(i - 1\)]\(k\
\*SuperscriptBox[\((1 - \[Alpha])\), \(k - 1\)]\)\) +
Ci (1 - \[Beta]) (1 - \[Alpha])^(i - 1) \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(k = i\), \(n\)]\(k\
\*SuperscriptBox[\(\[Beta]\), \(k - i\)]\)\)];
\[Lambda]vec[[n + 1]] = Ci \[Alpha] \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(k = 1\), \(n\)]\(k\
\*SuperscriptBox[\((1 - \[Alpha])\), \(k - 1\)]\)\) +
n Ci (1 - \[Alpha])^n ;
\[Lambda]vec[[n + 2]] = Ci \[Alpha] \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(k = 1\), \(n\)]\(k\
\*SuperscriptBox[\((1 - \[Alpha])\), \(k - 1\)]\)\) +
n Ci (1 - \[Alpha])^n;
\[Lambda]vec // MatrixForm;
v = Table[Subscript[x, i], {i, 1, n + 1}];
constraints1 = Table[Subscript[x, i] > 0, {i, n + 1}];
constraints2 =
Table[Subscript[x, i + 1] - Subscript[x, i] > 0, {i, n}];
constraints3 = Table[Subscript[x, i] \[Element] Reals, {i, 1, n + 1}];
uvec = Table[0, {i, 1, n + 1}];
uvec[[1]] = Assuming[{Subscript[x, 1] > 0}, \!\(
\*SubsuperscriptBox[\(\[Integral]\), \(0\),
SubscriptBox[\(x\), \(1\)]]\(t\ PDF[udist, t] \[DifferentialD]t\)\)];
For[i = 2, i <= n + 1, i++,
uvec[[i]] =
Simplify[
Assuming[{Subscript[x, i - 1] < Subscript[x, i],
Subscript[x, i - 1] > 0, Subscript[x, i] > 0}, (1 - \[Alpha])^(
i - 1) \!\(
\*SubsuperscriptBox[\(\[Integral]\),
SubscriptBox[\(x\), \(i - 1\)],
SubscriptBox[\(x\), \(i\)]]\(t\ PDF[udist, t] \[DifferentialD]t\)\)]]];
uvec // MatrixForm;
u = \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(i = 1\), \(n +
1\)]\(uvec[\([\)\(i\)\(]\)]\)\);
\[CapitalPhi] = Table[0.0, {n + 2}, {n + 1}];
\[CapitalPhi][[2, 1]] = \[Alpha] cR;
For[j = 1, j <= n,
j++, \[CapitalPhi][[1, j]] = -cF (1 - \[Beta]) \[Beta]^(j - 1)];
For[i = 2, i <= n,
i++[For[j = 1, j <= i - 1,
j++, \[CapitalPhi][[i, j]] = cR (1 - \[Alpha])^(j - 1) \[Alpha]]]];
For[i = 1, i <= n,
i++[For[j = i, j <= n,
j++, \[CapitalPhi][[i, j]] = -cF (1 - \[Alpha])^(
i - 1) (1 - \[Beta]) \[Beta]^(j - i)]]];
For[i = 1, i <= n,
i++, \[CapitalPhi][[i, n + 1]] = -cF (1 - \[Alpha])^(
i - 1) \[Beta]^(n - i)];
For[j = 1, j <= n,
j++, \[CapitalPhi][[n + 1, j]] = cR (1 - \[Alpha])^(j - 1) \[Alpha]];
For[j = 1, j <= n,
j++, \[CapitalPhi][[n + 2, j]] = cR (1 - \[Alpha])^(j - 1) \[Alpha]];
\[CapitalPhi][[n + 1, n + 1]] = -cF (1 - \[Alpha])^n;
\[CapitalPhi][[n + 2, n + 1]] = cR (1 - \[Alpha])^n;
\[CapitalPhi] // MatrixForm;)
(*OPTIMAL INSPECTION TIMES OF PERFECT OF PERFECT INSPECTIONS WHICH \
ARE EVENLY SPREAD*)
(n = 4;
\[Alpha] = 0.4;
\[Beta] = 0.1;
cR = 1000.;
Co = 10000.;
Cs = 2500.;
Ci = 400.;
cF = 200.;
H = 200;
udist = UniformDistribution[{0, H}];
updfdist = PDF[udist, t];
ucdfdist = CDF[udist, t];
Clear[Uunif];
Clear[LL];
v = Table[Subscript[x, i], {i, 1, n + 1}];
constraints1 = Table[Subscript[x, i] > 0, {i, n + 1}];
constraints2 =
Table[Subscript[x, i + 1] - Subscript[x, i] > 0, {i, n}];
constraints3 = Table[Subscript[x, i] \[Element] Reals, {i, 1, n + 1}];
Uunif[L_] = Assuming[{L > 0, L <= H}, (cR + cF) (\!\(
\*SubsuperscriptBox[\(\[Integral]\), \(0\), \(L\)]\(t\ PDF[udist,
t]\ \[DifferentialD]t\)\) - L CDF[udist, L]) +
cF (L - (n L)/(n + 1)) CDF[udist, (n L)/(n + 1)] + \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(i = 1\), \(n - 1\)]\(\((Ci + cF\ \((
\*FractionBox[\(\((i + 1)\)\ L\), \(n + 1\)] -
\*FractionBox[\(i\ L\), \(n + 1\)])\))\)\ CDF[udist,
\*FractionBox[\(i\ L\), \(n + 1\)]]\)\) + cR L - n Ci - (Co - Cs)];
{maxvalunif, repr1} = NMaximize[ {Uunif[L], L > 0 , L <= H} , {L}]
Clear[LL];
LL = L /. Last[ NMaximize[ {Uunif[L], L > 0, L <= H} , {L}]];
Clear[startsol];
startsol = Table[0.0, {1}, {n + 1}];
startsol = Table[N[(j LL)/(n + 1)], {j, 1, n + 1}];
)
(*Global optimal planning horizon when n PERFECT inspections are \
scheduled*)
(n = 4;
\[Alpha] = 0.4;
\[Beta] = 0.1;
cR = 1000.;
Co = 10000.;
Cs = 2500.;
Ci = 400.;
cF = 200.;
H = 200;
Clear[gwperfect];
Print["Profit function for n inspections at x1, x2, ..., xn"];
gwperfect[n_] =
Assuming[
Flatten@{constraints1, constraints2,
Subscript[x, n + 1] <= H}, (cR + cF) (\!\(
\*SubsuperscriptBox[\(\[Integral]\), \(0\),
SubscriptBox[\(x\), \(n + 1\)]]\(t\ PDF[udist,
t]\ \[DifferentialD]t\)\) -
Subscript[x, n + 1] CDF[udist, Subscript[x, n + 1]]) +
cF (Subscript[x, n + 1] - Subscript[x, n]) CDF[udist, Subscript[
x, n]] + \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(i = 1\), \(n - 1\)]\(\((Ci + cF\ \((
\*SubscriptBox[\(x\), \(i + 1\)] -
\*SubscriptBox[\(x\), \(i\)])\))\)\ CDF[udist,
\*SubscriptBox[\(x\), \(i\)]]\)\) + cR Subscript[x, n + 1] -
n Ci - (Co - Cs)]);
{maxvalperf, reprperf} =
NMaximize[{gwperfect[n],
Flatten[{constraints1, constraints2, Subscript[x, n + 1] <= H}]},
v, MaxIterations -> 800, AccuracyGoal -> 9, PrecisionGoal -> 8,
Method -> {"NelderMead", "InitialPoints" -> {startsol}}];
(*Global optimal planning horizon when n PERFECT inspections are \
scheduled*)
(n = 4;
\[Alpha] = 0.4;
\[Beta] = 0.1;
cR = 1000.;
Co = 10000.;
Cs = 2500.;
Ci = 400.;
cF = 200.;
H = 200.;
Clear[gwimperfect];
v = Table[Subscript[x, i], {i, 1, n + 1}];
constraints1 = Table[Subscript[x, i] < H, {i, 1, n + 1}];
constraints2 =
Table[Subscript[x, i + 1] - Subscript[x, i] > 0, {i, 1, n}];
gwimperfect[n_] =
Assuming[Flatten@{constraints1,
constraints2}, (cR +
cF) u + \[Lambda]vec.\[Psi]vec + \[Psi]vecc.\[CapitalPhi].xvec \
- (Co - Cs)];
{maxvalimperf, reprimperf} =
NMaximize[{gwimperfect[n],
Flatten[{constraints1, constraints2, Subscript[x, n + 1] <= H}]},
v, MaxIterations -> 2000, AccuracyGoal -> 9, PrecisionGoal -> 8,
Method -> {"NelderMead", "InitialPoints" -> {startsol}}];)
vivo = List[reprimperf]
Print[Uniformly "=", spread "=", inspection "=", times "=",
of "=", PERFECTO, "=" INSPECTIONS "="]
maxvalunif
startsol
Print[Globalo "=", optimal "=", inspection "=", times "=", of "=",
PERFECTO "=", INSPECTIONS "="];
maxvalperf
reprperf
Print[Globalo "=", optimal "=", inspection "=", times "=", of "=",
IMPERFECTO "=", INSPECTIOS "="];
maxvalimperf
reprimperf
ListPlot[startsol, reprperf, reprimperf]