- 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 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Fangjun Jiang
2011-9-19
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!