1
$\begingroup$

I need to minimize simple function with all variables are positive integers, but the out is the same as the input. No solution

    Clear[α, k, β, g];
g = (1 + Sqrt[5])/2;
f[α_, k_, β_, g_] := Abs[π - (α/β)*g^k;]
Assuming[α > 0 && k > 0 && β > 0 , 
 Minimize[f[α, k, β, g], {α, k, β}, 
  Integers]]

My version is 12.1

Any help

Thanks

$\endgroup$
6
$\begingroup$

First correct the definition of f (semicolon inside argument brackets)

g = (1 + Sqrt[5])/2;
f[\[Alpha]_, k_, \[Beta]_, g_] := Abs[\[Pi] - (\[Alpha]/\[Beta])*g^k]

Use NMinimize with constraints instead of assumptions:

NMinimize[{f[\[Alpha], k, \[Beta], g],Element[{\[Alpha], k, \[Beta]}, PositiveIntegers]}, {\[Alpha],k, \[Beta]} , MaxIterations -> 500]
(*{

0.0354583, {[Alpha] -> 3, k -> 3, [Beta] -> 4}}*)

addendum

Restricting the parameterrange {\[Alpha] -<10, k<10, \[Beta] <10} helps NMinimize finding the "right" minimum

NMinimize[{f[\[Alpha], k, \[Beta], g], \[Alpha] < 10, k < 10, \[Beta] < 10,Element[{\[Alpha], k, \[Beta]},PositiveIntegers]}, {\[Alpha],k, \[Beta]}  , MaxIterations -> 500]
(*{0.0000481329, {\[Alpha] -> 6, k -> 2, \[Beta] -> 5}}*) 
$\endgroup$
6
  • $\begingroup$ I wonder the upvoters. The answer is wrong. $\endgroup$ – user64494 Oct 29 '20 at 10:54
  • 1
    $\begingroup$ Indeed this answer is wrong. If you take the square of f and later the sqrt of the minimum, you can even use Minimize. f2[\[Alpha]_, k_, \[Beta]_, g] = (\[Pi] - (\[Alpha]/\[Beta])*g^k)^2 // ExpandAll; {{min, vars} = Minimize[{f2[\[Alpha], k, \[Beta], g], 0 < \[Alpha] < 300, 0 < k < 10, 0 < \[Beta] < 200, Element[{\[Alpha], k, \[Beta]}, Integers]}, {\[Alpha], k, \[Beta]}], Sqrt[min] // N} gives 8.4126*10^-6 as minimum of f. Minimum shows to be for k == 1 and it tends to zero. Use 262000 < \[Alpha] < 263000, 134000 < \[Beta] < 136000 in above cmd, set k=1. $\endgroup$ – Akku14 Oct 29 '20 at 16:06
  • 1
    $\begingroup$ @Akku14 Nothing is wrong! If you take the same parameter range \[Alpha] < 10, k < 10, \[Beta] < 10 as I did , you' ll get the solution given in my answer! $\endgroup$ – Ulrich Neumann Oct 29 '20 at 20:04
  • $\begingroup$ @user64494 It worked for me $\endgroup$ – Ahmed Kamal Kassem Oct 30 '20 at 3:53
  • $\begingroup$ @Ulrich Neumann, the OP is looking for the global minimum for {alpha,beta, k} are PositiveIntegers. This global minimum is not 0.0000481329 as you got with a restricted parameter range. In fact it is as i wrote "Minimum shows to be for k == 1 and it tends to zero" , although it never reaches exact zero. If you take a restricted parameter range, you don't answer the OP and you don't give " the "right" minimum" as you stated. $\endgroup$ – Akku14 Oct 30 '20 at 6:48
4
$\begingroup$

The infimum under consideration equals zero. Put k=1, then you approximate a number Pi/g==2*Pi/(1+Sqrt[5]) by a rational number \[Alpha]/\[Beta]. This can be done with an arbitrary accuracy, e.g.

RealAbs[FromContinuedFraction[ContinuedFraction[(2 \[Pi])/(1 + Sqrt[5]), 
 20]] - (2 \[Pi])/(1 + Sqrt[5])] // N
(*2.22045*10^-16*)
FromContinuedFraction[ContinuedFraction[(2 \[Pi])/(1 + Sqrt[5]),20]]
(*107070177060/55145018711*)
$\endgroup$
1
  • $\begingroup$ Even simpler: N[RealAbs[ Rationalize[(2 Pi)/(1 + Sqrt[5]), 10^-30] - (2 Pi)/(1 + Sqrt[5])], 30] performs 6.33234721355549660014137078117*10^-31. $\endgroup$ – user64494 Oct 29 '20 at 16:10

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.