Advertisement
MatsGranvik

Linear programming square root times constant

Apr 5th, 2020
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. (*start*)
  2. a = 1;
  3. b = 0;
  4. nn = 200;
  5. Monitor[TableForm[
  6. L2 = Table[
  7. LinearProgramming[
  8. Table[1/n, {n, 1, k}], {Table[
  9. If[n == 1, k, 1], {n, 1, k}]}, {{1, 0}},
  10. Table[If[n == 1, {-1, 1}, {-a*(n - 1), a + b*(n - 1)}], {n, 1,
  11. k}]], {k, 1, nn}]];, k]
  12. t1 = Table[Sum[If[L2[[n, k]] <= -1, 1, 0], {k, 2, n}], {n, 2, nn}]
  13. t2 = Table[Round[-1 + Sqrt[2]*Sqrt[((1 + a)*(-1 + n))/a]], {n, 2, nn}]
  14. Show[ListLinePlot[t1, PlotStyle -> Red], ListLinePlot[t2]]
  15. t1 - t2
  16. Count[%, 0] + 1
  17. (*end*)
  18.  
  19.  
  20. (*version 2, 3.5.2020*)
  21.  
  22. (*start*)a = 1;
  23. b = 0;
  24. nn = 200;
  25. Monitor[TableForm[
  26. L2 = Table[
  27. LinearProgramming[
  28. Table[1/n, {n, 1, k}], {Table[
  29. If[n == 1, k, 1], {n, 1, k}]}, {{1, 0}},
  30. Table[If[n == 1, {-1, 1}, {-a*(n - 1), a + b*(n - 1)}], {n, 1,
  31. k}]], {k, 1, nn}]];, k]
  32. t1 = Table[Sum[If[L2[[n, k]] <= -1, 1, 0], {k, 2, n}], {n, 2, nn}]
  33. t2 = Table[Round[-1 + 2 Sqrt[-1 + n]], {n, 2, nn}]
  34. Show[ListLinePlot[t1, PlotStyle -> Red], ListLinePlot[t2]]
  35. t1 - t2
  36. Count[%, 0] + 1
  37. (*end*)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement