What to be chosen c so that all elements of matrix B will be a round number. B=A.c; where A is the matrix of non integers.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello All,
Please guide me , if there is any system of equation s.t B=A.c; I need to find a fix value of c such that all elements of matrix B will be a round number. B=A.c; where A is the matrix of non integers numbers.
For example; B=[2.05;4.876,1.455] *c
I want to get value of c so that matrix B will be matrix of integer numbers.
4 commentaires
Réponses (1)
John D'Errico
le 5 Mai 2023
Modifié(e) : John D'Errico
le 5 Mai 2023
You want to find some scalar value c, such that for some given vector A, you want the product
A*c = B
to be purely a vector of integers? For some vectors, this is provably impossible, IF you allow the components of A to be irrational or even transcendental, AND you insist on an exact solution. For example just choose:
A = [sqrt(2) sqrt(3)]
There is no scalar constant c such that both c*sqrt(2) AND c*sqrt(3) will be integer. If you are willing to accept an approximate solution, then we could surely offer a solution, valid to within some tolerance. (I even recall writing code once to find a minimal solution for a similar APPROXIMATE problem.) But you explicitly said that is not acceptable, since @Rik suggested an approximate solution that will be extremely accurate, and you disagreed.
And of course, if some of the elements of A were possibly transcendental, then things get nastier yet, since there are some numbers where we don't even know their status.
So, no. You cannot solve the problem if you insist on an exact solution. And since some such problems may be indeterminate, then no solution can exist in general. Conversely, if you provide floating point numbers, then an answer is trivial. For example, in the problem you offer:
B=[2.05,4.876,1.455] *c
If you want an exact solution, then we could just start with c=1000. Once you did that, you would find:
A = [2050 4876 1455];
But then you could compute the gcd of the elements of that vector.
gcd(gcd(A(1),A(2)),A(3))
So the three integers in A are collaboratively co-prime. And that tells us the SMALLEST value of c to solve the problem is indeed 1000.
However, had you given the problem as:
B=[2.05,4.876,1.454]*c
Then now we see the solution can be reduced by the global gcd.
A = [2050 4876 1454];
gcd(gcd(A(1),A(2)),A(3))
And that means c = 1000/2 = 500 is a minimal solution.
Finally, IF you provide floating point numbers of that form, we would be forced to write the numbers in their binary form, because those numbers are in fact NOT stored as decimal numbers, but as binary numbers. The n we could form them as a sum of positive and negative powers of 2. Having done that, the solution would again be easy, but not quite so clean.
Again, I'll go back to your example. Having provided the numbers as:
A = [2.05,4.876,1.455];
Now I'll use my num2bin tool. (It should be posted on the file exchange.) And we can see that 2.05, as stored in MATLAB, can be represented as the sum:
format long g
A1 = [1 -5 -6 -9 -10 -13 -14 -17 -18 -21 -22 -25 -26 -29 -30 -33 -34 -37 -38 -41 -42 -45 -46 -49 -50];
sum(2.^A1)
Similarly, we can write each of those numbers as an expansion of positive an negative powers of 2.
A2 = [2 -1 -2 -3 -10 -16 -17 -21 -24 -27 -28 -30 -31 -32 -34 -37 -39 -40 -41 -42 -46 -47 -49 -50];
sum(2.^A2)
A3 = [0 -2 -3 -4 -6 -10 -11 -12 -13 -15 -17 -18 -19 -24 -26 -30 -31 -32 -33 -35 -37 -38 -39 -44 -46 -49];
sum(2.^A3)
Based on that expansion, we can see the number c = 2^50 could be applied to all three of this numbers, to now result in an integer. If we did that, then
Aapprox = [sum(2.^(A1 + 50)),sum(2.^(A2 + 50)),sum(2.^(A3 + 50))]
And converting them to symbolic form, gcd tells us they are relatively co-prime.
gcd(sym(Aapprox))
So the SMALLEST possible number you could use to scale all three of those numbers, having represented them in double precision and stored them as doubles is 2^50.
4 commentaires
Rik
le 6 Mai 2023
You are ignoring the point. The point is that what you ask is mathematically impossible to answer in general.
But for your specific example you can attempt to determine the number of digits, after which 10^NumberOfDigits is your starting point. Perform the multiplication and use gcd in a loop to determine by what you should divide your c. You may want to check how gcd deals with negative numbers.
Walter Roberson
le 6 Mai 2023
Question:
is -3.9743 exactly - 39743/10000 (base 10 precise notation), or is it "some indeterminate number between -397425/100000 inclusive and -397435/100000 exclusive (scientific notation, significant digits), or is it -3.974299999999999943867123874952085316181182861328125 exactly? Because the last of those is what MATLAB is going to use.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!