Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

I have a function code. I want to take your advice.

1 Ansicht (letzte 30 Tage)
Brian Kim
Brian Kim am 16 Okt. 2017
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
function nn_ewn=optim_ewn(c_ewn)
case_ewn=case_one_ewn_gen(c_ewn);
a_cost=[];
for ii=1:1:size(case_ewn,2)
tmp_ewn=case_ewn{ii};
[t_cost t_Ic t_current t_a2]=find_cost(tmp_ewn);
u=fitdist(t_Ic,'normal');
wu=u.sigma; wn=u.mu;
while 1
ste=sum(tmp_ewn);
tmp2_ewn=tmp_ewn
Hy=t_Ic-wn;
v1=max(Hy); v1_pos=find(Hy==v1);
v2=min(Hy); v2_pos=find(Hy==v2);
v4_pos=find(t_Ic==max(t_Ic));
v5_pos=find(t_Ic==min(t_Ic));
Ht=sort(t_Ic(:));
v6_pos=find(t_Ic==Ht(2));
if abs(v1) >= abs(v2)
d=abs(ceil(v1/v2))
elseif abs(v2) > abs(v1)
d=abs(ceil(v2/v1))
end
tmp3_ewn=tmp2_ewn;
if (tmp2_ewn(v1_pos) == 4 && tmp2_ewn(v2_pos) == 4) || (tmp2_ewn(v1_pos) == 12 && tmp2_ewn(v2_pos) == 12)
if (tmp2_ewn(v5_pos) == 4 && tmp2_ewn(v6_pos) == 4) || (tmp2_ewn(v5_pos) == 12 && tmp2_ewn(v6_pos) == 12)
tmp3_ewn=tmp2_ewn;
break
elseif (tmp2_ewn(v5_pos) == 4 && tmp2_ewn(v6_pos) ~= 4) || (tmp2_ewn(v5_pos) ~= 12 && tmp2_ewn(v6_pos) == 12)
tmp3_ewn(v5_pos)=tmp2_ewn(v5_pos)+d;
tmp3_ewn(v6_pos)=tmp2_ewn(v6_pos)-d;
elseif (tmp2_ewn(v5_pos) ~= 4 && tmp2_ewn(v6_pos) == 4) || (tmp2_ewn(v5_pos) == 12 && tmp2_ewn(v6_pos) ~= 12)
tmp3_ewn(v5_pos)=tmp2_ewn(v5_pos)-d;
tmp3_ewn(v6_pos)=tmp2_ewn(v6_pos)+d;
end
elseif (tmp2_ewn(v1_pos) == 4 && tmp2_ewn(v2_pos) ~= 4) || ...
(tmp2_ewn(v1_pos) ~= 4 && tmp2_ewn(v2_pos) == 4) || (tmp2_ewn(v1_pos) ~= 4 && tmp2_ewn(v2_pos) ~= 4) || ...
(tmp2_ewn(v1_pos) == 12 && tmp2_ewn(v2_pos) ~= 12) || ...
(tmp2_ewn(v1_pos) ~= 12 && tmp2_ewn(v2_pos) == 12) || (tmp2_ewn(v1_pos) ~= 12 && tmp2_ewn(v2_pos) ~= 12)
if (min(tmp2_ewn) >= 4 || max(tmp2_ewn) <= 12) && ...
(tmp2_ewn(v4_pos) >= 4 || tmp2_ewn(v5_pos) <= 12)
tmp3_ewn(v1_pos)=tmp2_ewn(v1_pos)-d;
tmp3_ewn(v2_pos)=tmp2_ewn(v2_pos)+d;
if tmp3_ewn(v1_pos) < 4 || tmp3_ewn(v2_pos) > 12
for jj=1:1:length(t_Ic)
v3_pos=find(t_Ic==Ht(jj)); % v3_pos is second minimum
if (tmp2_ewn(v3_pos) == 4) || (tmp2_ewn(v3_pos) == 12) %R
tmp_ewn=tmp2_ewn;
continue
elseif (tmp2_ewn(v3_pos) ~= 4) || (tmp2_ewn(v3_pos) ~= 12)
tmp3_ewn(v5_pos)=tmp2_ewn(v5_pos)+d;
tmp3_ewn(v3_pos)=tmp2_ewn(v3_pos)-d;
break
end
end
end
end
end
[g_cost g_Ic g_current g_a2]=find_cost(tmp3_ewn);
u1=fitdist(g_Ic,'normal');
if wu > u1.sigma
if min(tmp3_ewn) < 4
n=length(tmp3_ewn);
tmp3_ewn(v4_pos)=4;
tmp3_ewn(n)=ste-sum(tmp3_ewn(1:end-1));
end
if max(tmp3_ewn) > 12
n=length(tmp3_ewn);
tmp3_ewn(v5_pos)=12;
tmp3_ewn(n)=ste-sum(tmp3_ewn(1:end-1));
end
if (min(tmp3_ewn) >=4 || max(tmp3_ewn) <= 12) || (min(tmp3_ewn) >=4 && max(tmp3_ewn) <= 12)
wu=u1.sigma;
wn=u1.mu;
t_Ic=g_Ic;
tmp_ewn=tmp3_ewn;
end
continue
elseif wu < u1.sigma
gt_ewn=tmp_ewn
gt_cost=g_cost;
gt_Ic=g_Ic;
break
end end
a_cost=[a_cost,gt_cost];
Ic_cell{ii}=gt_Ic;
n_ewn{ii}=gt_ewn;
end
n=length(n_ewn)
mp_pos=find(a_cost==min(a_cost));
nn_ewn=n_ewn{mp_pos};
First, there are arbitrary row vectors (tmp_ewn) and corresponding row vectors of 't_Ic'. The purpose of this code is to find the row vector (gt_ewn) with the smallest standard deviation of t_Ic. However, I do not think that this code will calculate the final minimum row vector, but rather that it will output as soon as the standard deviation of the previously obtained row vector is small.
Umm.. Maybe I'm missing something. Please let me know if you have any additional questions about my question.

Antworten (0)

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!