1
$\begingroup$

I do not know how to code the following.

Suppose you have a list lst={x1,...,xn}and you need to find a number $Z$, to a given digits precision such that

Z * lst={y1,..,yn}

in which all $y_i$ are integers. I am clueless.

Thanks in advance.

Edit: To be more precise, given a list of numbers lst={x1,...,xn}and a parameter $\varepsilon>0 $ I want to find the smallest real number $Z$ such that for each $i \leq n$ we have $\mid Z\cdot x_i-\text{Round}(z\cdot x_i) \mid<\varepsilon $. Here Round$(x)$ denotes the closest integer to $x$.

$\endgroup$
4
  • $\begingroup$ Are your X floating point or rational? $\endgroup$ – MikeY Mar 16 '20 at 23:02
  • $\begingroup$ the $x$ values are the result of a rational list times $\pi/180$ $\endgroup$ – Victor Gustavo May Mar 16 '20 at 23:09
  • $\begingroup$ So you don't want an all integer list, you want an all "almost integer" list where they are all with $\varepsilon$ of an integer, correct? You want to find the minimum $Z$ that satisfies it? $\endgroup$ – MikeY Mar 17 '20 at 2:47
  • $\begingroup$ Yes, precisely. That is what I am looking for $\endgroup$ – Victor Gustavo May Mar 17 '20 at 13:52
1
$\begingroup$

Here is a list of rationals:

n=20; listRats = RandomInteger[{1, 10}, n]/RandomInteger[{1, 10}, n];

You can find your integer the Least Common Multiple of all the denominators of the rationals, so that

LCM @@ Denominator[listRats]*listRats

is the desired list of integers.

$\endgroup$
6
  • $\begingroup$ What if my list is not made up of rationals, but I wanted some degree precision, namely 10 digits. How could I transform my list into a list of rationals? so that I can use this $\endgroup$ – Victor Gustavo May Mar 16 '20 at 23:20
  • $\begingroup$ You said your list was composed of rational numbers times $\pi$/180, so multiply by 180/$\pi$. Otherwise you can rationalize the list using Rationalize[list, inc]. $\endgroup$ – bill s Mar 16 '20 at 23:27
  • $\begingroup$ Thanks, I did so. But my result is always an integer, which is not always the case for the minimum $z$ that works $\endgroup$ – Victor Gustavo May Mar 16 '20 at 23:32
  • $\begingroup$ If it is not working, please show an example of how it fails. But really, look at the help for Rationalize, this is the function you want. $\endgroup$ – bill s Mar 17 '20 at 0:51
  • $\begingroup$ It does work, but is not quite the answer to the problem. This is because this solution will only return the smallest integer $z$ such that z * lst is a integer list, what I need is the smallest positive real $z$. $\endgroup$ – Victor Gustavo May Mar 17 '20 at 1:05
1
$\begingroup$
qlst = Table[RandomInteger[{1, 10}]/RandomInteger[{1, 10}], 20]
z = Apply[LCM, qlst]
nlst = z*qlst
d = Apply[GCD, nlst]
lst = nlst/d
$\endgroup$
1
$\begingroup$

Not a full answer, just a clear statement of the problem. It is actually pretty interesting.

Create a set of integer denominators (what really matters) in a 2D space.

SeedRandom[1234]; den = Table[RandomInteger[{5, 25}], {2}];
1/den
(* {1/6, 1/25} *)

Find the least common multiplier lcm, which is also your value of $Z$ when $\varepsilon=0$

lcm = LCM @@ den
(* 150 *)

Plot $Z$ as you vary it over the range {0, lcm}

ParametricPlot[z/den, {z, 0, lcm}, Frame -> True, 
         GridLines -> {Range[0, (lcm/den)[[1]]], 
                       Range[0, (lcm/den)[[2]]]
                       }]

enter image description here

You can see that it almost hits the {4,1} grid coord and others. We can plot that. Set $\varepsilon=0.1$

eps = 0.1;
Plot[Norm[z/den - Round[z/den], Infinity], 
    {z, 0, lcm}, 
    Epilog -> Line[{{0, eps}, {lcm, eps}}]
    ]

enter image description here

So $Z$ about 24 or so (eyeballing it) is your value.

Around each grid crossing is a $D$-dimensional cube centered on the crossing with side lengths $\varepsilon$. The problem is to find the first cube intersected by the vector, knowing that it is bounded by when the vector length = lcm.

It might be possible to brute force it, but lcm can explode as the number of terms increases. Again, interesting problem!

$\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.