Plotting points from different parts of function to one plot

1 view (last 30 days)
How do I get the answers for roots, fzero, and the bisect function (I know they're all the same) to have points on the fplot I used in the beginning of the main function?
Editor:
function main clear all; clc; format compact global count
fplot(@f,[-2 1.5]) line('XData',[-2 1.5], 'YData',[0 0])
count = 1; roots([1 1 -2 -1]) disp(count)
count = 1; fzero(@f, -1.5) fzero(@f, 0) fzero(@f, 1) disp(count)
count = 1; a = bisect(@f, -2, -1, 1e-15) b = bisect(@f, -1, 1, 1e-15) c = bisect(@f, 1, 1.5, 1e-15) disp(count)
end
function [y]=f(x) global count y = x^3 + x^2 - 2*x - 1; count = count +1; end
function [r]=bisect(f, rL, ru, tol) while abs(ru-rL)>tol r = (rL + ru)/2; yL=f(rL); yr = f(r); if yL*yr<0; ru=r; else rL = r; end end end
Command Window:
ans = -1.8019 1.2470 -0.4450 1 ans = -1.8019 ans = -0.4450 ans = 1.2470 68 a = -1.8019 b = -0.4450 c = 1.2470 301
note: i need just the answers and a, b, and c to have points on the plot. Not the count.
Thanks!

Answers (0)

Community Treasure Hunt

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

Start Hunting!