- You have capital X and low case x. Don't mix them.
- size(X) will return two values for scalar, vector or 2-D matrix. The statement "for j=1:1:size(X)" will use the first value returned by size(X) function. But it will be better if you specify it like size(X,1) or size(X,2) depending on your need.#
Controlling X variable when using Fmincon
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi,
I have a problem where I want to reference previous iterations of Fmincon to use in current function evaluations. For example, the function looks something like this in pseudocode:
[log_value] = function (params)
for i=1:1:num_days
temp_indicator_vector = indicator_vector{1,i};
for j=1:1:size(X) if indicator_vector(j) == 0 x(j) = x_old(j) end end
.... calculate log_value based on x
So, the question is how do I save the previous iteration of x as x_old so that I can use it in the current? I know I can write each iteration to the disk and read it back into Matlab, but I am hoping to do it in memory to keep the computation as fast as possible.
Any help would be appreciated,
Ed
0 Commenti
Risposte (2)
Fangjun Jiang
il 19 Set 2011
After the iteration, just use x_old=x;
Do you know that you can assign a matrix to another matrix, as long as they are in the same size? Like this:
x_old=1:10;
x=rand(1,10);
x_old=x;
Two other things,
0 Commenti
Vedere anche
Categorie
Scopri di più su Get Started with Optimization Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!