0
AB = {{9.19, -7.67}, {9.59, -7.32}, {9.81, -7.99}, {12.53, -9.98},
{7.40, -6.26}, {8.03, -6.94}, {9.40, -7.56}, {9.71, -7.63}, {8.15,
-6.89}, {11.57, -9.48}, {11.82, -9.67}, {10.97, -9.15}, {7.57,
-6.20}, {11.50, -8.91}, {8.06, -6.13}, {8.65, -7.17}, {8.39, -7.01},
{14.04, -11.65}, {9.71, -8.14}, {8.19, -6.85}, {7.70, -6.22}, {8.37,
-6.85}, {8.18, -6.41}, {8.81, -7.29}, {10.78, -8.27}, {10.05, -8.79},
{8.00, -6.25}, {7.29, -6.21}, {9.22, -6.95}, {12.49, -9.80}, {8.3,
-6.61}, {7.14, -5.72}, {6.56, -5.27}, {11.54, -9.71}, {10.43, -7.92},
{8.65, -6.95}, {7.54, -6.06}, {7.93, -6.52}, {9.70, -7.80}, {9.86,
-7.73}};

Fin[x_, a_, b_, A_, B_, p_, i_] := 
 UnitStep[A^2 B^2 - ((B^2 Cos[p]^2 + A^2 Sin[p]^2) (x[[i, 1]] - 
        a)^2 + 2 Sin[p] Cos[p] (B^2 - A^2) (x[[i, 1]] - a) (x[[i, 2]] - 
        b) + (B^2 Sin[p]^2 + A^2 Cos[p]^2) (x[[i, 2]] - b)^2)]

FinTotal[x_, a_, b_, A_, B_, p_] := 
 Sum[Fin[x, a, b, A, B, p, i], {i, 1, Length[x]}]

m = -0.8;
p = ArcTan[m];
MinX = Min[AB[[All, 1]]];

{aMin, AMin, BMin} = {a, A, B} /. 
  NMinimize[{A B, 
     FinTotal[AB, a, m a, A, B, p] == 0.9 Length[AB] && MinX < a && 
      0 < B < A < a/Cos[p] }, {a, A, B}][[2]]

Simplify::time: Time spent on a transformation exceeded 300.` seconds, and the transformation was aborted. Increasing the value of TimeConstraint option may improve the result of simplification. >>

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
M Walker
  • 1
  • 1
  • 1
    Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Michael E2 Jan 21 '16 at 19:50
  • 2
    You can format inline code and code blocks by selecting the code and clicking the {} button above the edit window. The edit window help button ? is also useful for learning how to format your questions and answers. You may also find this this meta Q&A helpful – Michael E2 Jan 21 '16 at 19:50

1 Answers1

1

Just forbid the symbolic treatment by defining a numerical function:

x = {{9.19, -7.67}, {9.59, -7.32}, {9.81, -7.99}, {12.53, -9.98}, \
{7.40, -6.26}, {8.03, -6.94}, {9.40, -7.56}, {9.71, -7.63}, {8.15, \
-6.89}, {11.57, -9.48}, {11.82, -9.67}, {10.97, -9.15}, {7.57, \
-6.20}, {11.50, -8.91}, {8.06, -6.13}, {8.65, -7.17}, {8.39, -7.01}, \
{14.04, -11.65}, {9.71, -8.14}, {8.19, -6.85}, {7.70, -6.22}, {8.37, \
-6.85}, {8.18, -6.41}, {8.81, -7.29}, {10.78, -8.27}, {10.05, -8.79}, \
{8.00, -6.25}, {7.29, -6.21}, {9.22, -6.95}, {12.49, -9.80}, {8.3, \
-6.61}, {7.14, -5.72}, {6.56, -5.27}, {11.54, -9.71}, {10.43, -7.92}, \
{8.65, -6.95}, {7.54, -6.06}, {7.93, -6.52}, {9.70, -7.80}, {9.86, \
-7.73}};

FinTotNew[a_?NumericQ, b_, A_, B_, p_] := 
 Tr[UnitStep[
     A^2 B^2 - ((B^2 Cos[p]^2 + A^2 Sin[p]^2) (#[[1]] - a)^2 + 
                 2 Sin[p] Cos[p] (B^2 - A^2)  (#[[1]] - a) (#[[2]] - b) + 
                (B^2 Sin[p]^2 + A^2 Cos[p]^2) (#[[2]] - b)^2)] & /@ x]

m = -0.8;
p = ArcTan[m]
MinX = Min[x[[All, 1]]]
NMinimize[{A B, FinTotNew[a, m a, A, B, p] == 0.9 Length[x] && MinX < a && 
           0 < B < A < a/Cos[p]}, {a, A, B}]

(* {1.6247, {a -> 9.5597, A -> 3.89245, B -> 0.417397}} *)
Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
  • Your definition of Fin differs from the one in the question. What is the Tr doing there? – Sjoerd C. de Vries Jan 21 '16 at 20:51
  • @SjoerdC.deVries I rearranged the function, but kept the same name. Hope it's clearer now (I only renamed it). Tr replaces the Sum in the old FinTotal – Dr. belisarius Jan 21 '16 at 20:56
  • I had only read your answer up to the _?NumericQ you added and then I started to note some differences. Didn't see you had been combining the two functions. But have you now actually answered the question in the title? – Sjoerd C. de Vries Jan 21 '16 at 21:03
  • @SjoerdC.deVries I thought it was clear enough. Added half a line explaining it at the top. "O tempora! O terseness!" – Dr. belisarius Jan 21 '16 at 21:06
  • The point is, the _?NumericQ trick is usefully the answer to functions complaining about not being able to symbolically user-defined functions (like explained in this answer to our Pitfalls question). That's not the error message here, and the question is not how to get this stuff to run, but to explain the error message. – Sjoerd C. de Vries Jan 21 '16 at 21:09
  • @SjoerdC.deVries Simplify[ ] takes too long working on the sum of UnitStep[ ]. Why? I don't know. Who can predict which ways a black box is going? – Dr. belisarius Jan 21 '16 at 21:12
  • Why was Simplify called in the first place? I usually expect to see the NMinimize::nnum message to come up almost immediately in these situations. – Sjoerd C. de Vries Jan 21 '16 at 21:18
  • @SjoerdC.deVries Why? is a bold question. Who knows? But it does: Trace[NMinimize[{A B, FinTotal[AB, a, m a, A, B, p] == 0.9 Length[AB] && MinX < a && 0 < B < A < a/Cos[p]}, {a, A, B}][[2]], _Simplify] returns Simplify[-36. + UnitStep[A^2 B^2 - (-11.65 + 0.8 a)^2 (0.609756 A^2 + 0.390244 B^2) - (14.0 .... May be it's trying to compile it. – Dr. belisarius Jan 21 '16 at 21:56
  • @SjoerdC.deVries off the record, after scanning the trace I found in the presolve stage OptimizationNMinimizeDumptmpequal = Simplify /@ (OptimizationNMinimizeDumpequal /. OptimizationNMinimizeDumpsol) Which means it's trying to simplify the equality constraints- – Dr. belisarius Jan 21 '16 at 22:50
  • Ah, right. Good to know. – Sjoerd C. de Vries Jan 21 '16 at 23:00
  • Thanks to you both...for answering my question AND for editing the code to "fix" the issue. – M Walker Jan 25 '16 at 17:56