The fact that your first iteration (for Fitted_Curve and Error_Vector at least) works and the the subsequent ones don't tells me that you are not properly updating values between iterations. Not a C issue, per se, but a flaw in your translation (you would probably need to make the same update between iterations in matlab). Also, your sum/sse is not matching (I think they should be the same -- confrim please) between matlab and C, so that looks like a problem too. Again, full code please.