Using fminsearch in a loop
이전 댓글 표시
Hi,
What I want to do is find the minimum value of the variable, penalty, below using fminsearch. I am trying to get one value of penalty for each simulation (each row of R), instead of doing it manually by repeatedly inserting the maximum value of opportunity, as the new penalty value.
R is a 2 by 60 matrix made up of rates, that represents 1 simulation per row with the initial value the same for each simulation.
R = R./100;
initialfixed = R(1,1);
PVfixedinitial = zeros(1,1);
PVfixednew = zeros(1,1);
opportunity = zeros(1,1);
principle = 1;
for i=1:size(R,1)
x = fminsearch(Difference,0.3);
end
for i=1:size(R,1)
for j=1:size(R,2)
PVfixedinitial(i,j) = (initialfixed*principle)/R(i,j);
PVfixednew(i,j) = (R(i,j)*principle)/R(i,j);
opportunity(i,j) = PVfixedinitial(i,j)-PVfixednew(i,j);
Difference(i,j) = @(penalty) opportunity(i,j) - penalty;
if Difference(i,j)>0
initialfixed = Rmatrix(i,j);
end
end
initialfixed = Rmatrix(1,1);
end
Any help will be much appreciated. Thanks.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Performance and Memory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!