loop for equation a*b-c*d*(p-1)=1

5 vues (au cours des 30 derniers jours)
rjnt Kaur
rjnt Kaur le 12 Avr 2013
I need matlab loop code for equation a*b-c*d*(p-1)=1 where a nad c are randomly selected and b,d and p are calculated previously...loop must satisfy the equation and then display a and c

Réponse acceptée

Yao Li
Yao Li le 12 Avr 2013
b=1;
d=2;
p=3;
c=rand(10);
for i=1:length(c)
a(i)=1+c(i)*d*(p-1)/b;
fprintf('a=%d c=%d\n',a(i),c(i))
end
  2 commentaires
Walter Roberson
Walter Roberson le 12 Avr 2013
This does not randomly select "a"... but randomly selecting both "a" and "c" is unlikely to ever find a solution. See discussion in the original of this thread http://www.mathworks.co.uk/matlabcentral/answers/71707-need-help-on-equation-a-b-c-d-t-1-1
Walter Roberson
Walter Roberson le 12 Avr 2013
Algebraic correction:
a(i)=(1+c(i)*d*(p-1))/b;

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by