How to solve two-equations two-unknowns expecting a unique positive integer value for each variable?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mehdi Alipour M.
am 27 Jun. 2021
Kommentiert: Walter Roberson
am 29 Jun. 2021
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
2 Kommentare
Akzeptierte Antwort
Walter Roberson
am 27 Jun. 2021
Bearbeitet: Walter Roberson
am 28 Jun. 2021
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 Kommentare
Walter Roberson
am 29 Jun. 2021
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])
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
vpa(x)
vpa(y)
dx = double(x); dy = double(y);
mask = imag(dx) == 0 & imag(dy) == 0 & real(dx) >= 0 & real(dy) >= 0;
dx(mask)
dy(mask)
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Systems of Nonlinear Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





