# Linear regression and gradient descend equations

I'm pretty new to ML and was starting out with linear regression combined with gradient descend.

This is the equation I was trying to achieve using javascript-

And this is what I came up with in js-

      function algorithmify(){
let sumHDiff=hypotheses();
if(Math.round(hypotheses())!=0){
let sumHDiffMult=hypothesesWithMult();
T0-=0.0001*sumHDiff/points;
T1-=0.0001*sumHDiffMult/points;

console.log(T0,T1);
}
}

function hypotheses(){
let sum=0;
for(var i=0;i<points;i++){
let hypo=T0+(T1*X[i]);
let diff=hypo-Y[i];
diff*=diff;
sum+=diff;
}
return sum;
}
function hypothesesWithMult(){
let sum=0;
for(var i=0;i<points;i++){
let hypo=T0+(T1*X[i]);
let diff=hypo-Y[i];
diff*=diff;
mult=diff*X[i];
sum+=mult;
}
return sum;
}


I tried to match the code with the equation and even though I haven't done good variable naming, I'm pretty sure it is following the equation correctly.

But the result of $$T0$$ and $$T1$$ representing theta 0 and theta 1 first outputs very large negative numbers and after a few iterations, output $$-infinity$$ both times.

Any help would be greatly appreciated!