This is my modified regula falsi code
clear all; clear clc;g = 9.81; %acceleration m/s^2
m = 68.1; %mass, kg
t = 20; % time, seconds
f = @(c) g*m./c.*(1-exp(-c/m*t))-93.71;c = 2:20;plot (c, f(c))xlabel('c = 2:20')ylabel('Velocity formula in terms of c')title('Plot of velocity function with respect to c')a = 4; b = 8;error = 1;mold = 1;SF = 6;i = 1;F = f(a);G = f(b);while (1) m = (a*G - b*F)/(G-F); if F*f(m) < 0 b = m; G = f(m); if F*f(m) > 0 F = F/2; end else a = m; F = f(m); if f(a)*f(m) > 0 G = G/2; end end error = abs ((m-mold)/m); if error < 0.5*10^-SF break end mold = m; i = i + 1; %iteration counter
endverse3 = [num2str(m(end)),' is our (c) value.'];disp (verse3)verse = ['There were ' num2str(i), ' iterations done'];disp (verse)verse2 = ['The error is ', num2str(error(end))];disp (verse2)
Here is my regula falsi code
clear all; clear clc;g = 9.81; %acceleration m/s^2m = 68.1; %mass, kgt = 20; % time, secondsf = @(c) g*m./c.*(1-exp(-c/m*t))-93.71;c = 2:20;plot (c, f(c))xlabel('c = 2:20')ylabel('Velocity formula in terms of c')title('Plot of velocity function with respect to c')a = 4; b = 8;error = 1;mold = 1;SF = 6;i = 1;while (1) m = (a*f(b)-b*f(a))/(f(b)-f(a)); mbis(i) = m; if f(a)*f(m)<0; b = m; else a = m; end error = abs ((m-mold)/m); if error < 0.5*10^-SF; break end mold = m; i = i + 1; %iteration counterendverse3 = [num2str(m(end)),' is our (c) value.'];disp (verse3)verse = ['There were ' num2str(i), ' iterations done'];disp (verse)verse2 = ['The error is ', num2str(error(end))];disp (verse2)
Best Answer