Finding Set Of Answers For ONE Equation Involving SEVERAL Unknown Variables In a Discrete Data Zone
Afficher commentaires plus anciens
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
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!