How to concatenate output of fmincon in a loop

I am trying to write a script that minimizes an objective function,Gibbstot, over a range of two variables, xa and T, where xa is from 0 to 1 and T is from 500 to 1500. I have nested a for loop of xa inside a for loop of T. Fmincon is utilized inside my inner for loop. I am trying to sort the 3D answer matrix by one of the components, fs, for values in between 0 and 1.
I would then like to put these values in a separate solution vector that I can plot versus T.
This is what I have so far. Any help would be greatly appreciated!
if true
% code
end%Specify bounds
lb=10e-15 * [1 1 1]
ub=1 * [1 1 1]
%Make a guess, order of vector is [xas,xal,fs]
x0=[0.5,0.5,0.5]
%Specify options
options = optimoptions(@fmincon,...
'Display','iter','Algorithm','interior-point');
%looping over temperature
answer = zeros(10,5,5);
T=linspace(500,1500,10);
xa =linspace(0,1,5);
for i = 1:10
for j=1:5
T_current = T(i);
xa_current = xa(j);
[x,fval] = fmincon(@(x)Gibbstot(x,T_current),x0,[],[],[],[],lb,ub,@(x)confun(x,xa_current),options);
%x [xas xal fs]
if x(3)>=0.01 && x(3)<0.99
solution(i,1)=x(1)
solution(i,2)=x(2)
end
break
end
answer

3 Comments

Could you format your text so that it shows up as code?
Sorry about that, this should be more readable
What's wrong with what you have? It would be better if you pre-allocated "solution" prior to the loop,
solution=nan(10,2);
but other than that, there's no obvious defect.

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 6 Dec 2014

Edited:

on 6 Dec 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!