Nested for and while loop

I want to generate matrix [a] and I want to the value [a] in while loop.
A=randi(2,2);
b=A*transpose(A);
c=chol(b,'lower');
p=normrnd(0,1,[1,10]);
q=p(p>0); z=q(1:2);
E1=c*transpose(z);
E=transpose (E1);
K=[67.3061 -8.1429;-8.1429 59.1633]
b=[0;4];
for i=1:length(E)
a(:,:,i)=E(i)*K
x(:,1)=[0;0];
n=20;
r(:,1)=b-a(:,:,i)*x
d(:,2)=r(:,1)
k=1;
while (k<n)
p=transpose(d(:,k+1))*a(:,:,i)*d(:,k+1)
q=(transpose(r(:,k))*r(:,k));
s(k+1)=q/p
x(:,k+1)=x(:,k)+s(k+1).*d(:,k+1)
u=a(:,:,i)*d(:,k+1)
v=s(k+1).*u
r(:,k+1)=r(:,k)-v
if r(:,k+1)<=0.001
break;
end
w=transpose(r(:,k+1))*r(:,k+1);
w1=transpose(r(:,k))*r(:,k);
c(:,k+1)=w/w1;
l=d(:,k+1)
g=(w/w1)*l
d(:,k+2)=r(:,k+1)+g
k=k+1;
end
end

1 Commento

Dyuman Joshi
Dyuman Joshi il 21 Mag 2021
What exactly is the problem that you are facing?

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Richiesto:

il 3 Apr 2021

Commentato:

il 21 Mag 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by