Nested for and while loop

2 次查看(过去 30 天)
rakesh kumar
rakesh kumar 2021-4-3
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

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by