How to display all values of an iteration?

조회 수: 16 (최근 30일)
Mary Fasulo
Mary Fasulo 2020년 1월 30일
댓글: Mary Fasulo 2020년 1월 30일
hi so this is my code, currently it only displays the root and the number of bisections, but I need it to also display the value of each iteration, I'm not sure how to do this. Any help would be much appreciated!Capture.JPG
  댓글 수: 1
KSSV
KSSV 2020년 1월 30일
편집: KSSV 2020년 1월 30일
Attach your code..not an image snippet. Tell us what value you want to store?

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

채택된 답변

Ridwan Alam
Ridwan Alam 2020년 1월 30일
편집: Ridwan Alam 2020년 1월 30일
for i = 1:100
xc = (x1 + x2)/2;
if f(x1)*f(xc)<0
x2 = xc;
else
x1 = xc;
end
disp(['x1 = ',num2str(x1),',' ' x2 = ',num2str(x2)])
if abs(f(x1))<1e-6
break
end
end
you can also use fprintf() instead of disp().
hope this helps.
  댓글 수: 1
Mary Fasulo
Mary Fasulo 2020년 1월 30일
This works, thank you very much for your help!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by