How to join all points in the plot.
이전 댓글 표시
hello everyone, kindly help me to how to join all points with line.. here is my code.
function bisection
func=@(n) 40*n^1.5-875*n+35000;
maxit=50;
es=0.0001;
xl=50;
xu=100;
test = func(xl)*func(xu);
if test>0,error('no sign change'),end
mp = linspace(xl,xu);
fp = 40*mp.^1.5-875*mp+35000;
iter = 0; xr = xl; ea = 100;
fprintf('at iteration %2i\nxl = %2i\nxu = %2i\n ', 0, xl,xu)
fprintf(' iteration xl xu xr f(x) ea')
while (1)
% plot(iter,ea,'-*');axis ([0 20 -5 16])
xrold = xr;
xr = (xl + xu)/2;
hold on
plot(iter,ea,'r.-','markersize',20); axis([0 20 -5 40])
iter = iter + 1;
if xr ~= 0,ea = abs((xr - xrold)/xr) * 100;end
test = func(xl)*func(xr);
if test < 0
xu = xr;
elseif test > 0
xl = xr;
else
ea = 0;
end
if ea <= es | iter >= maxit,break,end
fprintf('\n%10i %14.4f %10.4f %10.3f %10.3f %9.3f', iter,xl,xu,xr,func(xr),ea)
end
fprintf('\n\nRoot is %7.3f after %2i iterations. \n\n', xr, iter)
root = xr; fx = func(xr);
fprintf('\nerror is = %17f\ntrue root=%17.4f\niteretions taken= %10.4f\n F(n)=%20.4f\n',ea,xr,iter,func(xr));
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Title에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!