Finding Set Of Answers For ONE Equation Involving SEVERAL Unknown Variables In a Discrete Data Zone

1 次查看(过去 30 天)
Suppose this equation: F(x,y)=9x+7y-60=0
The range which include just discrete numbers is: -5<x<10 and -5<y<10
All the possible answers in that range are: [x1,y1]=[2,6] and [x2,y2]=[9,-3]
I tried this code to find the answer set but it didn't find anything:
x=[-5:1:10];
y=[-5:1:10];
[X,Y]=ndgrid(x,y);
F=9.*x+7.*y-60;
idx=find(F==0);
[X(idx(:)),Y(idx(:))];
As below, If we change the range the way one of the answers come to first row, MATLAB find just that answer for us:
x=[2:1:10];
y=[6:1:14];
[X,Y]=ndgrid(x,y);
F=9.*x+7.*y-60;
idx=find(F==0);
[X(idx(:)),Y(idx(:))];
So the problem has found now. This code calculates F(xi,yj) just for the first row (i=1), so necessarily the only founded result is in the first row. Therefore we should improve our code the way counter calculates F1,1 to F16,16 then MATLAB search within all 16*16 elements of the F matrix. Now I don't know how to modify my code and want you to help me.
Thanks to you All

采纳的回答

Roger Stafford
Roger Stafford 2014-2-19
The line "F=9.*x+7.*y-60;" should be replaced by:
F=9.*X+7.*Y-60;
The way you had it, it only inspected the 16 pairs (-5,-5), (-4,-4), ..., (10,10) instead of checking all 256 possible pairings of x and y.
Assuming by 'discrete' you mean 'integer', there are much faster ways of finding solutions to the above equation rather than this brute force method. Equations of this type are known as Diophantine equations.
  1 个评论
SooShiant
SooShiant 2014-2-20
Thanks Roger. Its about 3 days I'm thinking on it. You solved it by a simple change in a second :)
Can you say the other ways of solutions to this kinds of equations?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by