Iterative Optimization with fminsearch
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have 2 time series data s and t. I have a function Error code:
function Error = Output (s,t,k) error = s*k(1)*k(2)*k(3)*k(4)-t; Error = sum(error^2); end
I have initial k, k0 = [a b c d e f]. So 6 parameters to vary. I want to create a loop that will keep fminsearch running for a range of values of k. That is, from k0 = [a0 b0 c0 d0 e0 f0] to k0 = [an bn cn dn en fn]. I also want to put different intialval:step:final value for each of a,b,c,d,e,f. So let a be from 1 to 5 with step of 1, b from 0.1 to 0.5 with step of 0.1 etc If the value of fval is less or equal to 1, I want the iteration or loop to end, otherwise the loop should continue to the end. This is the code I wrote so far and the error it gives me: t = a; s = c;
for k0 = [0.2 0.5 1 1.5]:[0.25 0.6 1.1 1.6]
[k,fval,exitflag,output] = fminsearch(@(k) suki(s, t, k), k0)
if fval <= 1
disp('Convergence has worked.')
elseif fval >= 1
disp('The convergence is not good enough')
end
end The error it gives is: Attempted to access k(2); index out of bounds because numel(k)=1.
Can anyone help me please in implementing this?
Antworten (0)
Siehe auch
Kategorien
Mehr zu Optimization finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!