% question3.m % Find first three positive roots of % the function f(x) = tanh(x) + tan(x) % First define data for the plots x = linspace(0,12,100); % 100 points between 0 and 12 y1 = tanh(x); y2 = -tan(x); % plot intersections in window with % 0 <= x <= 12, and -2 <= y <= 2 plot(x,y1,'-', x,y2,'--'); axis([0,12,-2,2]); % note the square brackets % Estimate intervals on which the following % function f changes sign and find first 3 roots using fzero f = @(x) tanh(x) + tan(x); format long r1 = fzero(f, [2,3]) r2 = fzero(f, [5,6]) r3 = fzero(f, [8,10]) %r1 = fzero(f, 3) %r2 = fzero(f, 6) %r3 = fzero(f, 9) sr1 = secant(f, 2, 3, 0.5E-5, 10, true) sr2 = secant(f, 5, 6, 0.5E-5, 10, true) sr3 = secant(f, 8, 10, 0.5E-5, 10, true)