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

Guru
Guru 2013년 7월 7일
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 2013년 7월 7일
편집: dpb 2013년 7월 7일
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 2013년 7월 7일
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 2013년 7월 7일
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...

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2013년 7월 7일

0 개 추천

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;

카테고리

도움말 센터File Exchange에서 Downloads에 대해 자세히 알아보기

태그

질문:

2013년 7월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by