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!