can any one help me to plot this function and midpoint each time will be calculated ?

1 回表示 (過去 30 日間)
Eliza
Eliza 2017 年 10 月 16 日
can any one help me to plot this function and midpoint each time will be calculated ?
% % function [x,n2] = cal
fun='x^2-7*x+10';
a=1;
b=4;
TOL=0.01;
NO=100;
h = 10;
fx=2*TOL; n2=0;
j = 0;
while(abs(fx)>TOL)&&(n2<=NO)
x=a;
fa=eval(fun);
x=(a+b)/2;
fx=eval(fun);
n2=n2+1;
if(sign(fx)==sign(fa))
a=x;
else b=x;
end j=j+1; cArray(j)=x;
% plot(fx,'marker','*');
% hold on % plot(cArray)
% plot(b,fx,'marker','o')
% plot(fx,'marker','*');
% hold on; % plot(x);
% plot(b);
end
axis([-0.5 6 -0.5 6])
xL = xlim;
yL = ylim;
xlabel('x-axis')
ylabel('y-axis')
line([0 0], yL,'color','black');
%x-axis line(xL, [0 0],'color','black');
%y-axis end end
end

回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by