How do this Interactions
1 view (last 30 days)
Show older comments
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 Comments
Image Analyst
on 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
on 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...
Answers (1)
Image Analyst
on 7 Jul 2013
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;
0 Comments
See Also
Categories
Find more on Language Fundamentals in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!