0
$\begingroup$

Writing:

AbsoluteTiming[

 Ac = ImplicitRegion[{-200 < y - yc < 0, 
                      100 + y - yc < 4/3 x < 100 - y + yc, 
                      Cos[a] y - x Sin[a] > 0}, 
                     {x, y}];

 eqn = {(Integrate[y, {x, y} ∈ Ac] + 1920 π (3 yc - 395)) sc + 20 10^3 yc,
        (Integrate[x y, {x, y} ∈ Ac] + 144000 π (3 yc - 395)) sc,
        (Integrate[y^2, {x, y} ∈ Ac] + 1920 π (64350 + yc (3 yc - 790))) sc 
        - 10^3 (10^4 - 20 (yc - 200/3)) yc};

 FindRoot[eqn, {{a, 0.9, 0.9, 2 π}, {yc, 100, 0, 200}, {sc, 15, 0, 30}}]

 ]

I get:

{315.452, {a -> 1.45833, yc -> 128.483, sc -> 13.8217}}

It's clear that the time required for the calculation is excessive. How can the code be improved?

$\endgroup$
2
$\begingroup$

In under 5 seconds on my old laptop; you are using numerics in FindRoot, so use numerics everywhere:

f[a_, yc_, sc_?NumericQ] := {
  (NIntegrate[ y  Boole[y Cos[a] > x Sin[a]], {y, -200 + yc, yc}, {x, 3/4 (100 + y - yc), 3/4 (100 - y + yc)}] +  1920 π (3 yc - 395)) sc + 20 10^3 yc,
  (NIntegrate[x y Boole[y Cos[a] > x Sin[a]], {y, -200 + yc, yc}, {x, 3/4 (100 + y - yc), 3/4 (100 - y + yc)}] + 144000 π (3 yc - 395)) sc,
  (NIntegrate[y^2 Boole[y Cos[a] > x Sin[a]], {y, -200 + yc, yc}, {x, 3/4 (100 + y - yc), 3/4 (100 - y + yc)}] + 1920 π (64350 + yc (3 yc - 790))) sc - 10^3 (10^4 - 20 (yc - 200/3)) yc
  };

FindRoot[f[a, yc, sc], {{a, 1, 0.9, 2 π}, {yc, 100, 0, 200}, {sc, 15, 0, 30}}] // AbsoluteTiming

(* {4.74802, {a -> 1.45833, yc -> 128.483, sc -> 13.8217}} *)
$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.