why this loop is not working? Actually p_j value is not changing why?

조회 수: 1 (최근 30일)
RAJKUMAR SAHA
RAJKUMAR SAHA 2023년 3월 5일
편집: VBBV 2023년 3월 8일
n = input('please enter number of strips :');
for i = 1:n
for j = i
p_i = 0
p_j = p_i + D/(2*n)
epsilon_ci = (epsilon_max/xu)*(xu-p_j)
sigma_ci = 0.45*fc*[2*(epsilon_ci/0.002)-(epsilon_ci/0.002)^2]
p_i == p_j;
end
end
  댓글 수: 2
Dyuman Joshi
Dyuman Joshi 2023년 3월 5일
편집: Dyuman Joshi 2023년 3월 5일
"why this loop is not working?"
It is working.
"Actually p_j value is not changing why?"
Because you are over-writing p_j with every iteration.
It is difficult to make any suggestions as it is not clear what you are trying to do. Format your code properly, mention values of variables and specify what you want to do with this code.

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

답변 (2개)

Pritesh Shah
Pritesh Shah 2023년 3월 5일
Instead of p_j write p(j)

VBBV
VBBV 2023년 3월 8일
편집: VBBV 2023년 3월 8일
n = 10;% e.g. input number
epsilon_ci = 0.001;
epsilon_max = 0.01;
xu = 2;
fc = 100;
D = 1.1;
p_i = 0; %outside for loop
for i = 1:n
p_j(i) = p_i + D/(2*n);
epsilon_ci = (epsilon_max/xu)*(xu-p_j(i));
sigma_ci = 0.45*fc*(2*(epsilon_ci/0.002)-(epsilon_ci/0.002)^2);
p_i = p_j(i); % assign new p_i
end
p_j
p_j = 1×10
0.0550 0.1100 0.1650 0.2200 0.2750 0.3300 0.3850 0.4400 0.4950 0.5500
  댓글 수: 1
VBBV
VBBV 2023년 3월 8일
You require only one for loop, since the inner for loop will lead to only one iteration,

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

카테고리

Help CenterFile Exchange에서 Variables에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by