Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
challenge implementing for loop
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
KALYAN ACHARJYA
el 3 de Dic. de 2019
Editada: KALYAN ACHARJYA
el 3 de Dic. de 2019
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
Respuestas (0)
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!