Info
此问题已关闭。 请重新打开它进行编辑或回答。
challenge implementing for loop
2 次查看(过去 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!