Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
challenge implementing for loop
조회 수: 5 (최근 30일)
이전 댓글 표시
I have chanllenges implementing this code to run a loop from Tmax to Tmin and accepting or rejecting m based on if statement
theta = [0:90]';
M = [1800;400;1850;0.2;0.5]';
Dm = ref_coeff(M,theta);
Ds = Dm + (0.02*randn(size(Dm)) + 0);
T = [logspace(3,0)]';
Mint = M;
for T = max(T) : min(T)
Er = (abs(Ds - Dm))./(0.02);
E = sum(Er);
n1 = 25 .* randn(1,1) + 1800
m1 = 1500 + n1*(2000 - 1500)
n2 = 50 .* randn(1,1) + 400
m2 = 0 + n2*(1000 - 0)
n3 = 50 .* randn(1,1) + 1850
m3 = 1200 + n3*(2200 - 1200)
n4 = 0.05 .* randn(1,1) + 0.2
m4 = 0 + n4*(1 - 0)
n5 = 0.05 .* randn(1,1) + 0.5
m5 = 0 + n5*(1 - 0)
m = [m1;m2;m3;m4;m5]'
dm = ref_coeff(m,theta)
ds = dm + (0.02*randn(size(dm)) + 0)
En1 = (abs(ds - dm))./(0.02)
En = sum(En1)
Ec = En - E
if Ec(T) >= 0
fprintf('%d.\n',m)
elseif (exp(Ec(T)/T)) > randn(0,1)
fprintf('%d.\n',m)
end
end
댓글 수: 1
KALYAN ACHARJYA
2019년 12월 3일
편집: KALYAN ACHARJYA
2019년 12월 3일
Er=(abs(Ds - Dm))./(0.02);
E = sum(Er);
n1 = 25 .* randn(1,1) + 1800
m1 = 1500 + n1*(2000 - 1500)
n2 = 50 .* randn(1,1) + 400
m2 = 0 + n2*(1000 - 0)
n3 = 50 .* randn(1,1) + 1850
m3 = 1200 + n3*(2200 - 1200)
n4 = 0.05 .* randn(1,1) + 0.2
m4 = 0 + n4*(1 - 0)
n5 = 0.05 .* randn(1,1) + 0.5
m5 = 0 + n5*(1 - 0)
m = [m1;m2;m3;m4;m5]'
dm = ref_coeff(m,theta)
ds = dm + (0.02*randn(size(dm)) + 0)
En1 = (abs(ds - dm))./(0.02)
En = sum(En1)
Ec = En - E
These expressions are independent with T, still why you are keeping those assignment within for loop with the variation of T?
You can use the proper indexing, likewise
T=sort(T);
Mint=M;
for i=1:length(T)
if T(i)...
.........
end
end
답변 (0개)
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!