can any one help me to plot this function and midpoint each time will be calculated ?
1 view (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Categories
Find more on Line Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!