Hello @Sudhir_Nandamuru,
You need to make sure the formula is implemented correctly. Note that the regularization term is outside of the error term (pay attention to the square brackets that I have used to separate the two).
Therefore, you have loops for the error terms only, and after you complete calculating the error terms, you add the regularization term.
Raymond
PS: Next time, please just open a new thread for your own question, instead of writing replies in multiple threads.