Abstract-In this paper, first derivative of smooth function is defined by the optimal solution of a special optimization problem. In the next step, by using this optimization problem for nonsmooth function, we obtain an approximation for first derivative of nonsmooth function which it is called generalized first derivative. We then extend it to define generalized second derivative for nonsmooth function. Finally, we show the efficiency of our approach by evaluating derivative and generalized first and second derivative of some smooth and nonsmooth functions, respectively.