function fx = maclaurin(x,Ea_desired) %MACLAURIN approximates log(1+x/1-x) using the MacLaurin series expansion % % (this section is skipped to avoid giving away part of the solution) % % Inputs: % X: a scalar with -1 < X < 1 % EA_DESIRED: a scalar with the desired approximate error % % Output: % FX: a scalar containing the MacLaurin approximation % % Assumptions: % - the input is inside the interval (-1,1) % - the desired approximate error is strictly positive % check whether the input is valid if length(x)>1 error('function only works for scalars'); end if abs(x)>=1 error('abs(x) must be smaller than 1'); end max_order = 2000; new_term = Inf; fx = 0; i = 1; while (abs(new_term) >= abs(Ea_desired)) && (imax_order warning('the approximation does not satisfy the desired accuracy') end return;