Object recognition is considered a necessary part in many computer vision applications. Recently, sparse coding methods, based on representing a sparse feature from an image, show remarkable results on several object recognition benchmarks, but the precision obtained by these methods is not yet sufficient. Such a problem arises where there are few training images available. As such, using multiple features and multitask dictionaries appears to be crucial to achieving better results. We use multitask joint sparse representation, using dynamic coefficients to connect these sparse features. In other words, we calculate the importance of each feature for each class separately. This causes the features to be used efficiently and appropriately for each class. Thus, we use variance of features and particle swarm optimization algorithms to obtain these dynamic coefficients. Experimental results of our work on Caltech-101 and Caltech-256 databases show more accuracy compared with state-of-the art ones on the same databases.