Creating a loop for genearating matrix
Show older comments
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 301x1 matrices.
m = 1;
Y1 = y(2:301);
psi1 = [-y(1:300) u(1:300)];
theta1 = inv(psi1'*psi1)*psi1'*Y1
e1 = Y1 - psi1*theta1;
Vmin1 = e1'*e1
m=2;
Y2 = y(3:301);
psi2 = [-y(2:300) -y(1:299) u(2:300) u(1:299)]
theta2 = inv(psi2'*psi2)*psi2'*Y2
e2 = Y2 - psi2*theta2;
Vmin2 = e2'*e2
m=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'*Y3
e3 = Y3 - psi3*theta3;
Vmin3 = e3'*e3
m=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'*Y4
e4 = Y4 - psi4*theta4;
Vmin4 = e4'*e4
m=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'*Y5
e5 = 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?
2 Comments
Stephen23
on 22 Dec 2015
Why do you need a loop? What is wrong with the code above?
Divya Krishna Ramakrishna
on 22 Dec 2015
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!