The first time rlsupdate is called the value of P,phi are set to eye(2) and 0. in the line 15 of code you have inverse of eye(1)+phi'*P*phi. the eye(1) is just 1, so it becomes :
which is singular matrix (doesn't have inverse). (
) so the K become NaN. and after that P become NaN in line 17. and all goes wrong after that.
you only need to handle this problem in line 15 to solve this issue.
i think you mean:
K = P*phi*inv(eye(2)+phi'*P*phi);
theta = theta + K*(y-(phi'*theta));
P = P - P*phi*inv((eye(2) + (phi'*P*phi)))*phi'*P;
but there will be another problem after doing this. not for first time. first time it will run without problem. after first time because of line 20 :
phi become 2x1 vector. but the calculation in line 15,16 and 17 are for scalar phi. you shoud handle them correctly.
maybe post the equation for K,theta and P so that i can help.