Using fminsearch in a loop
Mostra commenti meno recenti
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.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Performance and Memory in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!