***********************************************************************
*
*     Derivative.f
*     A program created for Programming Workshop Spring 06
*     At Marlboro College taught by Jim Mahoney
*
*     Written by Jesse Welch
*     
*     This program will take input from the user about the function 
*     in question.  
*
*     Version History:
*     1.0 - Output trig function values from user input
*     1.1 - Added in logarithmic functions
*     2.0 - Added in the derivative option
*     3.0 - Added in the option for derivative values and functions
*     4.0 - Added in the option for polynomial differentiation
***********************************************************************
      program  Derivative
      
      real inx
      real const1
      real const2
      real const3
      real const4
      character*(3) func
      character pick1
      character pick2
      character variable
      
      write(*,*) 'Would you like to take the derivative of :'
      write(*,*) '(a) Trig or log function, (b) Polynomial'
      read(*,*) pick2


      if (pick2 .eq. 'a') then
         write(*,*) 'What is the function you would like to work with?'
         write(*,*) 'In the form constant, function, argument, variable'
         read(*,*) const1, func, const2, variable
         write(*,*) 'You have chosen '
         write(*,*) const1,'*', func,'(',const2, variable, ')'
         
*         if (func .eq. 'sin') then
*            write(*,*) ' You have chosen ', func
*         else if (func .eq. 'cos') then
*            write(*,*) 'You have chosen ', func
*         else if (func .eq. 'tan') then
*            write(*,*) 'You have chosen ', func
*         else if (func .eq. 'log') then
*            write(*,*) 'You have chosen ', func
*         else if (func .eq. 'ln ') then
*            write(*,*) 'You have chosen ', func
*         else if (func .eq. 'exp') then 
*            write(*,*) 'You have chosen ', func
*         endif
         
         
         write(*,*) 'Do you want the derivative (f)unction or (v)alue?' 
         read(*,*) pick1
*         write(*,*) pick1
         
         if (pick1 .eq. 'f') then       
            if (func .eq. 'sin') then
               write(*,*) 'You have chosen ', func
               write(*,*) 'And the derivative of ', func , ' is...'
               write(*,*) const1*const2,'*Cos(',const2,variable,')'
            else if (func .eq. 'cos') then
               write(*,*) 'You have chosen ', func
               write(*,*) 'And the derivative of ', func , ' is...'
               write(*,*) -1*const1*const2,'*Sin(',const2,variable,')'
            else if (func .eq. 'tan') then
               write(*,*) 'You have chosen ', func
               write(*,*) 'And the derivative of ', func , ' is...'
               write(*,*) const1*const2,'*1/Cos^2(',const2,variable,')'
            else if (func .eq. 'log') then
               write(*,*) 'You have chosen ', func
               write(*,*) 'And the derivative of ', func , ' is...'
               write(*,*) const1,'*(1/ln(10))','* (1/(',variable,'))'
            else if (func .eq. 'ln ') then
               write(*,*) 'You have chosen ', func
               write(*,*) 'And the derivative of ', func , ' is...'
               write(*,*) const1, '*(1/(',variable,'))'
            else if (func .eq. 'exp') then 
               write(*,*) 'You have chosen ', func
               write(*,*) 'And the derivative of ', func , ' is...'
               write(*,*) const1*const2,'(*exp(',const2,variable,'))'
            else if (func .eq. 'Sin') then
               write(*,*) 'You have chosen ', func
               write(*,*) 'And the derivative of ', func , ' is...'
               write(*,*) const1*const2,'*Cos(',const2,variable,')'
            else if (func .eq. 'Cos') then
               write(*,*) 'You have chosen ', func
               write(*,*) 'And the derivative of ', func , ' is...'
               write(*,*) -1*const1*const2,'*Sin(',const2,variable,')'
            else if (func .eq. 'Tan') then
               write(*,*) 'You have chosen ', func
               write(*,*) 'And the derivative of ', func , ' is...'
               write(*,*) const1*const2,'*1/Cos^2(',const2,variable,')'
            else if (func .eq. 'Log') then
               write(*,*) 'You have chosen ', func
               write(*,*) 'And the derivative of ', func , ' is...'
               write(*,*) const1,'*(1/ln(10))','* (1/(',variable,'))'
            else if (func .eq. 'Ln ') then
               write(*,*) 'You have chosen ', func
               write(*,*) 'And the derivative of ', func , ' is...'
               write(*,*) const1, '*(1/(',variable,'))'
            else if (func .eq. 'Exp') then 
               write(*,*) 'You have chosen ', func
               write(*,*) 'And the derivative of ', func , ' is...'
               write(*,*) const1*const2,'(*exp(',const2,variable,'))'
            else
               write(*,*) 'Inproper input'
            endif
            
         else if (pick1 .eq. 'v') then
            
            write(*,*) 'What x value are you interested in?'
            read(*,*) inx
            
            if (func .eq. 'sin') then
               write(*,*) 'You have chosen ', func
               write(*,*) 'And the value of the derivative of ', func ,
     $              ' at ', inx , ' is...'
               write(*,*) const1*const2*Cos(1.0*const2*inx)
            else if (func .eq. 'cos') then
               write(*,*) 'You have chosen ', func
               write(*,*) 'And the value of the derivative of ', func ,
     $              ' at ', inx , ' is...'
               write(*,*) -1.0*const1*const2*Sin(1.0*const2*inx)
            else if (func .eq. 'tan') then
               write(*,*) 'You have chosen ', func
               write(*,*) 'And the value of the derivative of ', func ,
     $              ' at ', inx , ' is...'
               write(*,*) const1*const2*(1.0/((Cos(1.0*const2*inx))*2))
            else if (func .eq. 'log') then
               write(*,*) 'You have chosen ', func
               write(*,*) 'And the value of the derivative of ', func ,
     $              ' at ', inx , ' is...'
               write(*,*) const1*(1/(LOG(10.0)))*(1.0/(inx))
            else if (func .eq. 'ln ') then
               write(*,*) 'You have chosen ', func
               write(*,*) 'And the value of the derivative of ', func ,
     $              ' at ', inx , ' is...'
               write(*,*) const1*(1.0/inx)
            else if (func .eq. 'exp') then 
               write(*,*) 'You have chosen ', func
               write(*,*) 'And the value of the derivative of ', func ,
     $              ' at ', inx , ' is...'
               write(*,*) const1*const2*Exp(1.0*const2*itx)
            else if (func .eq. 'Sin') then
               write(*,*) 'You have chosen ', func
               write(*,*) 'And the value of the derivative of ', func ,
     $              ' at ', inx , ' is...'
               write(*,*) const1*const2*Cos(1.0*const2*inx)
            else if (func .eq. 'Cos') then
               write(*,*) 'You have chosen ', func
               write(*,*) 'And the value of the derivative of ', func ,
     $              ' at ', inx , ' is...'
               write(*,*) -1.0*const1*const2*Sin(1.0*const2*inx)
            else if (func .eq. 'Tan') then
               write(*,*) 'You have chosen ', func
               write(*,*) 'And the value of the derivative of ', func ,
     $              ' at ', inx , ' is...'
               write(*,*) const1*const2*(1.0/((Cos(1.0*const2*inx))*2))
            else if (func .eq. 'Log') then
               write(*,*) 'You have chosen ', func
               write(*,*) 'And the value of the derivative of ', func ,
     $              ' at ', inx , ' is...'
               write(*,*) const1*(1/(LOG(10.0)))*(1.0/(inx))
            else if (func .eq. 'Ln ') then
               write(*,*) 'You have chosen ', func
               write(*,*) 'And the value of the derivative of ', func ,
     $              ' at ', inx , ' is...'
               write(*,*) const1*(1.0/inx)
            else if (func .eq. 'Exp') then 
               write(*,*) 'You have chosen ', func
               write(*,*) 'And the value of the derivative of ', func ,
     $              ' at ', inx , ' is...'
               write(*,*) const1*const2*Exp(1.0*const2*itx)
            else   
               write(*,*) 'Inproper input'           

            endif
            
         end if
      
      else
      
         write(*,*) 'What polynomial you would like differentiated?'
         write(*,*) 'In the form constant variable power'
         read(*,*) const3, variable, const4
         
         if (const4 .gt. 0) then
            const3 = const3*const4
            const4 = const4 - 1
            write(*,*) 'Your function is now ', const3,'*',
     $           variable,'^',const4
         else
            write(*,*) 'Your function is now zero.'
         endif
         
      end if
      
      end
      
      
