A system with 2 unknowns in Java or more.

Solved
Valerie54001 Posted messages 135 Registration date   Status Member Last intervention   -  
Valerie54001 Posted messages 135 Registration date   Status Member Last intervention   -
Hello,

I'm looking to automatically solve a system with 2 unknowns in Java, but I have no idea what function to use and I'm not even sure if it exists for this type of case.

In my example,

1st equation: X (M + 1) is closest to or equal to A compared to Y (N - 1); A can be between 1 and 9 inclusive.
2nd equation: Y (N + 1) is closest to or equal to A compared to X (M - 1); A can be between 1 and 9 inclusive.

So I would like to know if there is a way to get the values of M and N automatically by providing the result?
And if so, by what formula?

5 answers

KX Posted messages 19031 Status Moderator 3 020
 
Hello,

"is the closest or equal to A with respect to"
This is not very standard, and since the wording is not very precise, it could be interpreted in several different ways.

Do you have any examples?

Is your second equation a second, independent example from the first, or is it part of the same system of equations?
--
Trust does not exclude control.
0
Valerie54001 Posted messages 135 Registration date   Status Member Last intervention   1
 
Good evening KX,

I will try to be clearer.

I am looking for an equation to find possible values for M and N based on the following 2 situations, taking my problem in reverse by knowing which of X or Y is closest to or equal to A.

Knowing that X and Y are between 1 and 9 and loop (1,2,3,4,5,6,7,8,9,1,2 etc.....)

X represents (M +1), Y represents (N -1), A is a known value at the beginning for our first situation, I determine that X will be the closest to or equal to A.

For the second, Y represents (N +1), X represents (M -1), A is also a known value, I determine that Y will be the closest to or equal to A.
At this point we have:
(M +1) ; (N -1) =3
(N +1) ; (M -1) =9

Using the hammer/chisel method or heuristic, since I can determine if X or Y should be the closest to or equal to A, I get:
M=9 and N=3, that is:
(M +1) ; (N -1) =9
(9 +1) ; (3 -1) =9
(1) ; (2) =9 knowing that 10 does not exist it becomes 1 with the loop.
(1) ; (2) =9
1 is closer to 9 than 2.

(N +1);(M -2) =3
(3 +1);(9 -1) =3
(4) ; (8) =3
4 is closer to 3 than 8.

The equation or formula to be created is certainly complex because initially, it is necessary to determine which of X or Y or both are closest to the value A and then M and N should come out automatically.

I cannot make it clearer and less complex.

What do you think?
0
KX Posted messages 19031 Status Moderator 3 020
 
I say that basic Java will not offer any useful libraries for this type of processing; it will be based on basic loops, but everything will have to be done specifically for this need.

Afterwards, I'm not sure I understood everything; in my opinion, I'm still missing elements to understand your explanations...

"At this point we have: (M +1); (N -1) =3 (N +1); (M -1) =9"
I don't understand where the 3 and the 9 come from...
"1 is closer to 9 than 2"
If 10=1, then 1 is as close to 2 as it is to 9, right?

In my opinion, you shouldn't ask too many questions; there are two values to find between 1 and 10, which only makes 100 possible combinations.
So you iterate over the 100 pairs and look for the one that minimizes your fitness function in order to get the desired result.

It's brute force, so not optimized, but if you could at least come up with an algorithm that addresses the problem, I might be able to better understand it and see how to improve it for the future.
--
Trust does not exclude control.
0
Valerie54001 Posted messages 135 Registration date   Status Member Last intervention   1
 
I will try to answer your questions:
"At this point we have: (M +1); (N -1) =3 (N +1); (M -1) =9"
I don't understand where the 3 and the 9 come from...
The numbers 3 and 9 are values obtained after processing; they are not values set randomly.

"1 is closer to 9 than 2"
If 10=1 then 1 is also as close to 2 as to 9, right?
Be careful, X =1 Y=2 in this specific case, the one that is closest to 9 is indeed 1 while respecting the loop (1,2,3,4,5,6,7,8,9,1,2, etc.....)

Indeed 2 values with 100 pairs but with 2 equations.

As you said it's brute force that's why this line of code must be feasible or not!

If you think an algorithm could work then I will post a new topic!

KC, my goal is to set up n equations with n unknowns.

Ultimately, I will determine the priority of the result as well as A and from there M and N should appear by themselves.
0
Valerie54001 Posted messages 135 Registration date   Status Member Last intervention   1
 
Well, since there is no response, it's because I wasn't able to express myself properly despite my efforts.
I'll do it differently, thanks to those who took the time to try to understand my issue.
ériiic will be happy to close the topic.
0
Anonymous user
 
A takes an initialization value
L a list of objects

# Brute force on all possible values
For M varying from 1 to 9
...For N varying from 1 to 9
... ...Calculate M + 1, N - 1
... ...Calculate N + 1, M - 1
... ...Determine X = distance from M + 1 to A and Y = distance from N - 1 to A.
... ...If X < Y :
... ... ...Determine Y = distance from N + 1 to A and X = distance from M - 1 to A.
... ... ...If Y < X:
... ... ... ...Add to L the object (M, N, X case 1 and Y case 2)
# Processing the results
R first object of L
For the element of L:
...If X case 1 of l < X case 1 of R and Y case 2 of l < Y case 2 of R:
... ...R = l
# End
Display M and N of R

--
Helping is my nindo
0
Valerie54001 Posted messages 135 Registration date   Status Member Last intervention   1
 
Hello Help-Jason,

Wow!!

How do you prepare if X = Y?

The question is: how can I put it into practice? Because when searching online, I can only find software to hack passwords...
0
Anonymous user
 
In case 1, X must be closer to A than Y. If they are at the same distance and you want to include the result, simply replace the < with <=.

You can apply this in many programming languages if possible procedural. I'm particularly thinking of Python and C. In both cases, I can still help you.
0
Valerie54001 Posted messages 135 Registration date   Status Member Last intervention   1
 
I made progress on this thanks to Benjamin :)
0