% Class 10 - Root Solving % Coded by NFR on 9.26.2019 % % 1st Method: Graphical Approach % Sometimes works, labor intensive % but nice to see what's going on cd = 0.25; % kg/m t = 4; %s g = 9.81; %m/s^2 ftv = @(m) sqrt(g*m/cd)*tanh(sqrt(g*cd/m)*t)-36 fplot(ftv,[130 160]) xlabel('Mass (kg)') ylabel('Velocity (m/s)') % Solution by inspection is 142.7 % Works for simple, one time problems % If you need to process a lot of data or be % more accurate, we need an alogorithm % % Method 2: Using Numerical Methods % Problem 5.5 from the textbook f1 = @(x)-12-21*x+18*x.^2-2.75*x.^3; % (b) bisection [r_bisect,fx,~,iter_bisect] = bisect(f1,-1,0,1); fplot(f1,[-1 0]) hold on plot(r_bisect,fx,'ro') % (c) False position [r_fp,fx,~,iter_fp] = falsepos(f1,-1,0,1); plot(r_fp,fx,'b+') hold off % Let's see if the false position method % is more efficient iter_fp iter_bisect % Example of incremental search % Plot same function above with bigger x span fplot(f1,[-2,6]) % There appears to be multiple roots from % -2 to 6, let's use incremental search % to find them xb = incsearch(f1,-2,6,10000)