필터 지우기
필터 지우기

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