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

2 ビュー (過去 30 日間)
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 件のコメント
Sara Boznik
Sara Boznik 2021 年 6 月 27 日
Code looks fine, maybe you send the equations you have?
Mehdi Alipour M.
Mehdi Alipour M. 2021 年 6 月 28 日
t and g are my equations as you can find them in the code...

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2021 年 6 月 27 日
編集済み: Walter Roberson 2021 年 6 月 28 日
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 件のコメント
Mehdi Alipour M.
Mehdi Alipour M. 2021 年 6 月 28 日
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?
Walter Roberson
Walter Roberson 2021 年 6 月 29 日
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

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSystems of Nonlinear Equations についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by