How do this Interactions

I need make 28 interactions but one by one takes a long time so I think. If a make a for cycle it was very fast to calculate this:
a=0
b=1
inter=28
for k=1:inter
m=(a+b)/2;
end
my problem is to see that each cycle run if the value of m < b my = m and b remain again with the same initial value, if the value of m > b, b = m "to" assume the previous value of the interaction to perform interactions 28

4 Kommentare

Guru
Guru am 7 Jul. 2013
What?!?! I am not sure what you are expecting to see, in particular this sentence from your question makes no sense to me:
"my problem is to see that each cycle run if the value of m = m and b remain again with the same initial value, if the value of m b, b = m "to" assume the previous value of the interaction to perform interactions 28"
Please clarify in your best English possible
dpb
dpb am 7 Jul. 2013
Bearbeitet: dpb am 7 Jul. 2013
And, as part of that provide a small sample problem that illustrates what is desired...it can be as few as, say, 3 "interactions" (whatever they are) instead of 28 and probably suffice to make the point.
Provide the known input(s)/desired output(s) even if you have to do it all w/ pencil and paper owing to not knowing how to code up what you expect.
Image Analyst
Image Analyst am 7 Jul. 2013
I was thinking that the tag "bisection" might give us a clue, where he keeps bisecting some smaller and smaller range until he finally arrives at some target value, but I agree that the English is such that it's really impossible to tell what is wanted. I agree with dpb that a diagram would help. Upload one to http://snag.gy
dpb
dpb am 7 Jul. 2013
That's possibly true as the (a+b)/2 is a method of bisection, indeed. I was confounded by "interaction" but maybe "iteration" was intended instead--didn't think of that possible confusion in what is obviously not native English. I was also distracted by the comment that "it was very fast to calculate this" when the code posted actually is an infinite loop and that there are no signs of updating a or b nor any stopping criterion...
Ah, well, hopefully a clarification will ensue...

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 7 Jul. 2013

0 Stimmen

Any chance this is what you mean?
a = 0
b = 1
m(1) = b
numberOfIterations = 28
for k=1:numberOfIterations
m(k + 1) = (a + m(k)) / 2
end
plot(m, 'ro-', 'LineWidth', 2);
grid on;

Kategorien

Tags

Gefragt:

am 7 Jul. 2013

Community Treasure Hunt

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

Start Hunting!

Translated by