How can I use the subplot command to plot the root estimates vs iterations and the error vs iterations
조회 수: 1 (최근 30일)
이전 댓글 표시
this is my code:
Use bisection method to find the root
f = @(x) x.^3 - (9)*x.^2 + 3.8197
xl = -1000
xu = 1000
xm = (xl+xu)/2
error = 20
while error > 0.001
if (f(xm).*f(xl))<0
xu=xm
xm2 = (xl+xu)/2
error = (xm2-xm)/xm2
error = abs(error)
xm = xm2
else
xl=xm
xm2 = (xl+xu)/2
error = (xm2-xm)/xm2
error = abs(error)
xm = xm2
end
xm= (xl+xu)/2
end
the root is -0.6299 with error = 0.0757%
How can I collect the error and root estimate at each run, and use subplot command to plot 1: root estimates vs iterations and 2:error vs iterations\
thank you very much!
댓글 수: 0
답변 (1개)
darova
2021년 4월 4일
Try this
figure
hold on
while %condition
% some code
subplot(2,1,1)
plot(iter,root)
subplot(2,1,2)
plot(iter,error)
iter = iter + 1;
end
댓글 수: 4
참고 항목
카테고리
Help Center 및 File Exchange에서 Subplots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!