Hello All, I am new to matlab and i need to create a loop for my code below. Could yu please help me out in this. The input u and y are 301×1 matrices.
m = 1; Y1 = y(2:301);psi1 = [-y(1:300) u(1:300)];theta1 = inv(psi1'*psi1)*psi1'*Y1e1 = Y1 - psi1*theta1;Vmin1 = e1'*e1m=2;Y2 = y(3:301);psi2 = [-y(2:300) -y(1:299) u(2:300) u(1:299)]theta2 = inv(psi2'*psi2)*psi2'*Y2e2 = Y2 - psi2*theta2;Vmin2 = e2'*e2m=3;Y3 = [y(4:301)];psi3 = [-y(3:300) -y(2:299) -y(1:298) u(3:300) u(2:299) u(1:298)];theta3 = inv(psi3'*psi3)*psi3'*Y3e3 = Y3 - psi3*theta3;Vmin3 = e3'*e3m=4;Y4 = [y(5:301)];psi4 = [-y(4:300) -y(3:299) -y(2:298) -y(1:297) u(4:300) u(3:299) u(2:298) u(1:297)];theta4 = inv(psi4'*psi4)*psi4'*Y4e4 = Y4 - psi4*theta4;Vmin4 = e4'*e4m=5;Y5 = [y(6:301)];psi5 = [-y(5:300) -y(4:299) -y(3:298) -y(2:297) -y(1:296) u(5:300) u(4:299) u(3:298) u(2:297) u(1:296)];theta5 = inv(psi5'*psi5)*psi5'*Y5e5 = Y5 - psi5*theta5;Vmin5 = e5'*e5
I need to create a loop for generating psi everytime. Does anyone have any idea about how can we create it for the above code?
Best Answer