% A script with solutions to some questions from Math 230's second hour
% exam, and calls to test/demonstrate solutions that are functions.

%% Question 1.
% At x = 0, the derivative of 2x^3 - 3, 6x^2, is 0. Thus Newton's method
% will divide by 0 on its first attempt to refine the estimated root.


%% Question 2, Part A.
% The solution is really in file "countM.m", but here are some tests of it.
countM( 4 )         % The example from the test, result should be 4
countM( -4 )        % This should also produce 4
countM( 1000001 )   % x > 1,000,000 should produce 0


%% Question 2, Part B.
% The exam asks you to assume x already has a value, but for a real test
% I need to give it one. So this statement is good for demonstrating the
% exam solution, but isn't part of it:
x = input( 'Enter an x for countM ' );

% The answer to the actual question just requires an "if-else" statement to
% call "countM" or not according to the value of x:
if abs(x) > 1.62
    countM( x )
else
    fprintf( 'Illegal x\n' );
end


%% Question 4.
% The real solution is in file "printFunny.m". Here is a call to test it
% on the example given in the exam.
printFunny( [5,2,7,12,1] )