Why this loop is executing 4 times?

조회 수: 1 (최근 30일)
AVINASH SAHU
AVINASH SAHU 2022년 6월 7일
댓글: Voss 2022년 6월 7일
% For plane slider: H = Ho + a(1-x)
Ho = 1;
alpha = 0.1;
eps = 0.1;
a = 1.0;
lbar = 0.1;
SIGMA = 0:0.05:0.15;
sigma = zeros(1,length(SIGMA));
for j = 1:length(SIGMA)
sigma = SIGMA(j);
H = @(x) Ho + a*(1 - x); % For plane slider: H = Ho + a(1-x)
G1 = @(x) H(x).^3 + 3 .* H(x).^2 .* alpha + 3 .* H(x) .* alpha^2 + 3 .* H(x) .* sigma^2 + eps + 3*sigma^2*alpha + alpha^3 - 12*lbar^2 .* (H(x) + alpha);
G2 = @(x) 24 * lbar^3 .* tanh(H(x)./(2*lbar));
G3 = @(x) (12*lbar^2*alpha - eps - alpha^3 - 3*sigma^2*alpha) .* (1 - (tanh(H(x)./(2*lbar))).^2);
G = @(x) G1(x) + G2(x) + G3(x);
Hm1 = @(x) H(x).* (1 ./ G(x));
Hm2 = @(x) (1 ./ G(x));
IntHm1 = integral(Hm1,0,1);
IntHm2 = integral(Hm2,0,1);
Hm = IntHm1 / IntHm2;
P1 = @(x) 6 .* (1 ./ G(x)) .* (H(x) - Hm);
P2 = @(x) integral(P1,0,x);
% Calculating dimensionless load carrying capacity(W):
W(j) = integral(P2,0,1, 'ArrayValued', true)
% Calculating non dimensional Frictional Force(F):
F1 = @(x) (H(x).* P1(x)) ./2 + (1 ./ H(x));
F(j) = integral(F1,0,1)
% Calculating coefficient of friction(f):
f(j) = F(j)/W(j)
% Calculating non dimensional temperature rise(deltaT):
deltaT(j) = F(j)/Hm
% Calculating the center of pressure(Xbar):
Xbar1 = @(x) P2(x) .* x;
Xbar(j) = integral(Xbar1, 0, 1, 'ArrayValued', true)/W(j)
end

채택된 답변

Voss
Voss 2022년 6월 7일
SIGMA is of size 1-by-4, and the loop goes from 1 to length(SIGMA) (which is 4), so what else would you expect?
SIGMA = 0:0.05:0.15 % 1-by-4
SIGMA = 1×4
0 0.0500 0.1000 0.1500
for j = 1:length(SIGMA) % 1:4
disp(j)
end
1 2 3 4
  댓글 수: 4
AVINASH SAHU
AVINASH SAHU 2022년 6월 7일
Yes, thank you!
Voss
Voss 2022년 6월 7일
You're welcome!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by