How to solve two-equations two-unknowns expecting a unique positive integer value for each variable?

Hello Commuinty,
I hope you are doing well.
I've got two sets of equations, same orders but with different coeffiecients as following. m and n are -16.135571 and -130.15315, respectively and I haven't found any relationship between them yet. I want to solve this system so as ending up a unique positive integer number for each variable. Is this possible?
I've written the following code to solve it but at the end of the day what I end up with is just a set of complex numbers and I don't know that if possible answers are involved or not. Under what circumistances I could reach that point? do I need to use any predictor or what?? what if I find a correlation between the inputs or outputs??
Any suggestion would be appreciated. Thank you in advance...
m=-16.135571;
n=-130.15315;
% First equation coefficients
p00 = -16.17;
p10 = 0.0579;
p01 = 0.2456;
p20 = 0.00202;
p11 = 0.000276;
p02 = 0.1334;
p30 = -1.112e-05;
p21 = -0.002938;
p12 = 0.1167;
p03 = -1.882;
% Second equation coefficients
p00p = -131.1;
p10p = 0.2864;
p01p = 3.502;
p20p = -0.005359;
p11p = -1.929;
p02p = 8.532;
p30p = -4.325e-05;
p21p = 0.01226;
p12p = 0.7535;
p03p = -17.02;
syms x y
a=1;
b=90;
c=0.1;
d=0.5;
t=p00 + p10.*x + p01.*y + p20*x.^2 + p11.*x.*y + p02.*y.^2 + p30.*x.^3 + p21.*x.^2.*y + p12.*x.*y.^2 + p03.*y.^3==m;
g=p00p + p10p.*x + p01p.*y + p20p.*x.^2 + p11p.*x.*y + p02p.*y.^2 + p30p.*x.^3 + p21p.*x.^2.*y + p12p.*x.*y.^2 + p03p.*y.^3==n;
Eqns=[t,g];
S=solve(Eqns,[x y])
x=S.x
y=S.y
minmax = @(x,a,b) max(min(x,a),b); % restricts input X between a and b
minmax = @(y,c,d) max(min(y,c),d); % restricts input X between a and b

 Risposta accettata

t is a multinominal in x and y. You can treat it temporarily as a polynomial in x with constant coefficients. So you can solve(t, x) getting back 3 roots because it is a cubic in x.
You can now substitute the x into g, which will give you a polynomial in y of degree 9.
Because this will be a polynomial, the methods to find numeric approximations are well known. You will not be able to find closed form solutions, but the numeric approximations can be done to any desired precision.
All of which is to say that when you do the solve() and get out the 9 root() placeholders, then you can can vpa() and look at them. Not one of the solutions is nearly an integer. If one had been (say) 9+5e-15 then you would have room to suspect that maybe 9 exactly was a solution and the rest was round-off error... but none of the results are even close to integer.
And that means that there are no integer values that solve those particular equations.
There might be equations of that form with different coefficients that have integer solutions.

6 Commenti

If the task is to find two polynomials in x and y, one of which equals m and the other equals n, and the polynomials intersect at a point that is an integer x and integer y, and you are permitted to be arbitrary floating point coefficients, then the solution is easy.
Consider that you can construct
1*A + 1*B = m
1*A - 1*B = n
You can solve as A = (m+n)/2, B = (m-n)/2
Now take those A and B that you just got, and construct
A*x + B*y = m
A*x - B*y = n
And by simple comparison we can see that the solution must be x = 1, y = 1, which are integers.
First of all, thank you for your answers and follow-ups. I really appreciate it.
I've just realized that I'm allowed to have a decimal number, too. The only thing that I need to be concern about is the final solution which should be a unique number for both x and y. Considering this and your previous answer, I just didn't get one thing! Based on your saying I should take y as zero and solve (t,x) and etc. right?? or am I missing something here??
Regards
You have multinomials that require 9th roots of a polynomial to solve. If you are going to use polynomials and each variable must solve to a unique value, then your polynomials must be of degree 1 and not have x*y in them.
Now what you just maybe might mean is that you want the polynomial solutions to be such that only one of the solutions is real-valued. The equations you posted earlier have three real-valued solutions, which is consistent with the fact that polynomials with real coefficients must have an even number of complex-valued solutions (they come in conjugate pairs). With odd degree (9) and even number complex it follows that an odd number must be real-valued.
Is it possible to construct two multinominals with forms similar to your earlier ones, that equal m and n, and which have only a single real-valued solution? I would be relatively sure that it could be done, perhaps as little difference as flipping a couple of signs.
There, I changed one of the signs, and now there is only one real-valued solution.
m=-16.135571;
n=-130.15315;
% First equation coefficients
p00 = -16.17;
p10 = 0.0579;
p01 = 0.2456;
p20 = 0.00202;
p11 = 0.000276;
p02 = 0.1334;
p30 = -1.112e-05;
p21 = -0.002938;
p12 = 0.1167;
p03 = -1.882;
% Second equation coefficients
p00p = -131.1;
p10p = 0.2864;
p01p = 3.502;
p20p = -0.005359;
p11p = -1.929;
p02p = 8.532;
p30p = -4.325e-05;
p21p = 0.01226;
p12p = 0.7535;
p03p = -17.02;
syms x y
a=1;
b=90;
c=0.1;
d=0.5;
t= p00 + p10.*x - p01.*y + p20*x.^2 + p11.*x.*y + p02.*y.^2 + p30.*x.^3 + p21.*x.^2.*y + p12.*x.*y.^2 + p03.*y.^3==m;
g=p00p + p10p.*x + p01p.*y + p20p.*x.^2 + p11p.*x.*y + p02p.*y.^2 + p30p.*x.^3 + p21p.*x.^2.*y + p12p.*x.*y.^2 + p03p.*y.^3==n;
Eqns=[t,g];
S=solve(Eqns,[x y])
S = struct with fields:
x: [9×1 sym] y: [9×1 sym]
vpa(S.x)
ans = 
vpa(S.y)
ans = 
Actually, this model is related to a system with actual measurements where I used a curve fitting model to extract the polynomials. So, I don't think I'm allowed to change the signs. Now, I'm doing the retrieving process to reach a positive real-valued number for both x and y. When I look at the solutions out of vpa() I see that my answers are involved but with a tiny deviation which is fairly good enough. Maybe I can find a relationship between my variables or m,n and involve the numerical methods too to increase the precision. Maybe there is a suggestion that I need to consider in this regard??
By the way, how can I define my m,n as a matrices in this code in the case that I can just have the second solution of each variable as my true answers to save some time in Matlab calculations and finally end up with a neat matrix?
Well, if the task is to pick out the positive real solutions, just do that.
What you were talking about before was coming up with some equation relating the variables, without regard to what the equations looked like.
format long g
m=-16.135571;
n=-130.15315;
% First equation coefficients
p00 = -16.17;
p10 = 0.0579;
p01 = 0.2456;
p20 = 0.00202;
p11 = 0.000276;
p02 = 0.1334;
p30 = -1.112e-05;
p21 = -0.002938;
p12 = 0.1167;
p03 = -1.882;
% Second equation coefficients
p00p = -131.1;
p10p = 0.2864;
p01p = 3.502;
p20p = -0.005359;
p11p = -1.929;
p02p = 8.532;
p30p = -4.325e-05;
p21p = 0.01226;
p12p = 0.7535;
p03p = -17.02;
syms x y
a=1;
b=90;
c=0.1;
d=0.5;
t=p00 + p10.*x + p01.*y + p20*x.^2 + p11.*x.*y + p02.*y.^2 + p30.*x.^3 + p21.*x.^2.*y + p12.*x.*y.^2 + p03.*y.^3==m;
g=p00p + p10p.*x + p01p.*y + p20p.*x.^2 + p11p.*x.*y + p02p.*y.^2 + p30p.*x.^3 + p21p.*x.^2.*y + p12p.*x.*y.^2 + p03p.*y.^3==n;
Eqns=[t,g];
S=solve(Eqns,[x y])
S = struct with fields:
x: [9×1 sym] y: [9×1 sym]
x=S.x
x = 
y=S.y
y = 
minmax = @(x,a,b) max(min(x,a),b); % restricts input X between a and b
minmax = @(y,c,d) max(min(y,c),d); % restricts input X between a and b
vpa(x)
ans = 
vpa(y)
ans = 
dx = double(x); dy = double(y);
mask = imag(dx) == 0 & imag(dy) == 0 & real(dx) >= 0 & real(dy) >= 0;
dx(mask)
ans =
1.52492687976673
dy(mask)
ans =
0.522542922064927

Accedi per commentare.

Più risposte (0)

Prodotti

Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by