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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!