Nested for and while loop

조회 수: 1 (최근 30일)
rakesh kumar
rakesh kumar 2021년 4월 3일
댓글: Dyuman Joshi 2021년 5월 21일
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
Dyuman Joshi
Dyuman Joshi 2021년 5월 21일
What exactly is the problem that you are facing?

댓글을 달려면 로그인하십시오.

답변 (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