| |

VerySource

 Forgot password?
 Register
Search
View: 2645|Reply: 15

How to find the minimum difference between two linear functions?

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-25 17:20:01
| Show all posts |Read mode
Z = aX-bY (a, b are constants, X, Y are integers and a certain range exists) Find the minimum value of Z?
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-5 09:45:02
| Show all posts
From the equation point of view, it is a plane in a three-dimensional space. After limiting the range of x and y, a parallelogram of a space is obtained.
z is the smallest, that is, the lowest point of the space bounding box of the parallelogram
Since it is a linear relationship, the extreme values ​​all occur on the boundary. Calculate z using four boundary points in the x and y range.
Reply

Use magic Report

0

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-3-9 22:45:01
| Show all posts
This is the simplest linear programming (LP) problem and can be solved in many ways, such as the "graphing method".
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-4-26 10:30:01
| Show all posts
Still do not understand
Reply

Use magic Report

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-4-29 10:00:02
| Show all posts
Just judge the sign of a and b, if a is less than or equal to 0, take the largest plant of X, otherwise X takes the minimum value; if b is less than or equal to 0, take the smallest plant of Y, otherwise Y takes the maximum value. The Z value obtained in this way must be the smallest.
Reply

Use magic Report

0

Threads

5

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-4-29 18:15:01
| Show all posts
That is to say, Z is composed of two parts, aX and -bY. If both parts get the minimum value, the value of Z must be the smallest, and the minimum value of the two parts within a certain range is very easy to find, which is the above Too.
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-5-14 18:30:01
| Show all posts
Code running on Linux:

#include <iostream>

using namespace std;

int main ()
{
int a, b;
int X_min, X_max;
int Y_min, Y_max;
int Z;
int X, Y;
int doonce = 0;

cout << "Input a, b" << endl;
cin >> a >> b;
cout << "Input X_min, X_max" << endl;
cin >> X_min >> X_max;
cout << "Input Y_min, Y_max" << endl;
cin >> Y_min >> Y_max;
The
for (X = X_min; X <= X_max; X ++)
{
for (Y = Y_min; Y <= Y_max; Y ++)
{
if (doonce == 0)
{
Z = a * X-b * Y;
doonce = 1;
}
if (Z <(a * X-b * Y))
{
Z = a * X-b * Y;
}
}
}
cout << "The min of a * X-b * Y =" << Z << endl;
return 0;
}
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-5-15 15:45:01
| Show all posts
I forgot to add the absolute value
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-5-18 19:00:01
| Show all posts
By the way, the less-than sign is changed to a greater-than sign, otherwise it is the maximum value
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-5-22 10:00:02
| Show all posts
Z = aX-bY (a, b are constants, real numbers, X, Y are integers and there is a certain range) What is the minimum value of | Z |?
I forgot to add the absolute value in the front. Is this difficult to find the minimum value of | Z |?

If only the minimum value of Z is sought, as in the answer oflhempire, that is, the minimum value of ax minus the maximum value of by.

Thanks to thesuny00059program, in fact, in my case, X and Y may be a larger range, or may need to select two or more numbers in a set of real numbers as a and b to calculate So using the exhaustive method may result in orders of magnitude of calculation time. Now I want to find a way to find the minimum or close to the minimum | Z |.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list