Step 4:compute Cost