%  numint1.m
% Matlab file for Part 1 of Numeric Calculation of 
% Integrals module

disp('**********************************************')
disp('Part 1: Left-Hand and Right-Hand Sums')
disp('**********************************************')
disp('  ')    

    format long
    
    disp('--------------------------------------------')
    disp('Steps 1 and 2: ')
    disp('Answer the questions by using MATLAB comments ')
    disp('in your diary file. ')
    disp(' ')
    disp('To continue, type the word return and ')
    disp('hit enter!')
    disp(' ')
    
    keyboard;
    disp(' ')
    
    disp('---------------------------------------------')
    disp('Enter the integrand function to use in ')
    disp('steps 3 and 4: ')
    disp(' ')
    disp('  f = fcnchk(''(x^2+5)/6'', ''vectorized'' )  ')
    disp(' ')
    disp(' ')
    disp('To continue, type the word return and ')
    disp('hit enter!')
    disp(' ')
    
    keyboard;
    disp(' ')
    
    disp('--------------------------------------------')
    disp('Step 3: ') 
    disp('The command to compute the LHS for') 
    disp('n=5 rectangles is provided.  After ')
    disp('executing it, you need to modify it in ')
    disp('order to use n = 10 rectangles.')
    disp(' ')
    disp('Enter')
    disp(' ')
    disp('  f(0)*1.0 + f(1)*1.0 + f(2)*1.0 + ... ')
    disp('  f(3)*1.0 + f(4)*1.0 ')
    disp(' ')
    disp('---------------------------------------------')
    disp('Do your sums match those of the applet? ')
    disp('Answer using MATLAB comments in your diary file.')
    disp(' ')
    disp('To continue, type the word return and ')
    disp('hit enter!')
    disp(' ')
    
    keyboard;
    disp(' ')
    
    disp('---------------------------------------------')
    disp('Step 4: ')
    disp('Modify the commands above to calculate the ')
    disp('RHS approximations for n = 5 and n = 10 and ')
    disp('compare your results to those of the applet. ')
    disp(' ')
    disp('Give results by using MATLAB comments in')
    disp('your diary file.')
    disp(' ')
    disp('To continue, type the word return and ')
    disp('hit enter!')
    disp(' ')
    
    keyboard;
    disp(' ')
    
    disp('---------------------------------------------')
    disp('Step 5: ')
    disp('Answer the questions by using MATLAB comments in')
    disp('in your diary file.')
    disp(' ')
    disp('To continue, type the word return and ')
    disp('hit enter!')
    disp(' ')
    
    keyboard;
    disp(' ')
    
    disp('---------------------------------------------')
    disp('Step 6: ')
    disp('Below, find the commands that calculate a ')
    disp('left-hand sum. By changing the value of n and')
    disp('re-entering the commands, you can calculate the')
    disp('sum for the number of subintervals you desire.')
    disp('You can enter a new function f(x) and new ')
    disp('endpoints a and b to calculate an approximation')
    disp('to any integral. ')
    disp(' ')
    disp('Enter: ')
    disp(' ')
    disp('  clear f x a b n xpt; ')
    disp('  f = fcnchk(''(x^2+5)/6'', ''vectorized'' )  ')
    disp('  n = 40 ')
    disp('  a = 0, b = 5 ')
    disp('  delx = (b-a)/n; ')
    disp('  xpt = a: delx: b-delx; ')
    disp('  areas = f(xpt)*delx; ')
    disp('  LHS = sum(areas)  ')
    disp(' ')
    disp('------------------------------------------------')
    disp('Discuss how your results compare with those of')
    disp('the applet by using MATLAB comments in your ')
    disp('diary file.')
    disp(' ')
    disp('To continue, type the word return and ')
    disp('hit enter!')
    disp(' ')
    
    keyboard;
    disp(' ')
    
    disp('------------------------------------------------')
    disp('Step 7: ')
    disp('Change the function to f(x)=1/x and the interval')
    disp('to 1 < x < 3 in the LHS commands above and do ')
    disp('the calculations to fill in the table below. ')
    disp(' ')
    disp('  Subintervals n     LHS Approx to 1/x integral ')
    disp('         5                 1.2436008440')
    disp('        10                 ____________')
    disp('        20                 ____________')
    disp('        40                 ____________')
    disp(' ')
    disp('To continue, type the word return and ')
    disp('hit enter!')
    disp(' ')
    
    keyboard;
    disp(' ')
    
    disp('------------------------------------------------')
    disp('Step 8:')
    disp('Modify the commands above so that they calculate')
    disp('right-hand sums instead.  Then check that you')
    disp('get the same results for f(x) = (x^2 + 5)/6 that')
    disp('are calculated by the applet. ')
    disp(' ')
    disp('------------------------------------------------')
    disp('Discuss your results by using MATLAB comments')
    disp('in your diary file. ')
    disp(' ')
    disp('To continue, type the word return and ')
    disp('hit enter!')
    disp(' ')
    
    keyboard;
    disp(' ')
    
    disp('------------------------------------------------')
    disp('Step 9:')
    disp('Change the function to f(x)=1/x and the interval')
    disp('to 1 < x < 3 in your RHS commands and do the ')
    disp('calculations to fill in the table below. ')
    disp(' ')
    disp('  Subintervals n     RHS Approx to 1/x integral ')
    disp('         5                 0.9769341769')
    disp('        10                 ____________')
    disp('        20                 ____________')
    disp('        40                 ____________')
    disp(' ')
    
    disp(' ')
    disp('-------------------------------------------- ')
    disp('When you are ready to go on to part 2 ')
    disp('of this module, type: numint2.')
    disp(' ')
