# Re: Using fmincon with ODE

My differential equations are defined in the m.file ex13func1 as below.

function dcdt = ex13func1(t,c,a)
global n Km1 Km2 Km3 Kg1 Kg2 Kg3 Kc1 Kc2 a
dcdt(1,1)...... % All functions of a
dcdt(2,1)......
dcdt(i,1)....... % These are quite big functions
end

My differential equations (when solved) gives me a matrix in t & c; I want to maximize the first equations last c-value, i.e. c(end,1) by varying the components in a vector a.
My objective function then becomes:

function obj=myfun(a)
global c0array a
[t c]=ode15s(@ex13func1,[0 5], c0array,a);
obj=-c(end,1); % Maximize c by minimizing -c
end

My main script is:
clc, clf, clear all;
global n a Km1 Km2 Km3 Kg1 Kg2 Kg3 Kc1 Kc2 c0array aEG aCBH aBG

% 1.3.3 - The initial known values are defined
n=100; c0=0.6; aEG=7; aCBH=12; aBG=6; Km1=10; Km2=1; Km3=1; Kg1=1; Kg2=1;
Kg3=1; Kc1=20; Kc2=20;
a=[aEG,aCBH,aBG];
c0array=zeros(n,1);
c0array(n)=c0; % Initial condition for solver

% fmincon with inspiration from this forum!
options = optimset('Algorithm','interior-point');
a0 = [7;12;6]; % Random guess
Aeq = [1 1 1];
beq = 25; % The sum of the a?s must equal 25
cfinal = fmincon(@(a)myfun,a0,[],[],Aeq,beq,[0;0;0],[25;25;25],[],options);

Upon running the main script I get this message after a few seconds:

"Optimization terminated: first-order optimality relative error
less than options.TolFun, and relative constraint violation less
than options.TolCon."

I think my problem lies in the passing of variables, namely a. I have never used Matlabs built-in optimization before, so i am quite stuck! If you want to see the m.files let me know!

Thanks againg for helping with this (probally quite basic) problem.
.

## Relevant Pages

• Re: Need a little script help
... my problem lies. ... But I did note that your add records sub script changes the layout and ... Creating new records will also lose the place in the Loop (although the ...
(comp.databases.filemaker)
• Create user with mailbox
... I do have code which does this, but the problem lies with the number of E mail addresses that are ... I've tried adding a line in my user creation script that specifies a single mail ... but although the script runs without error, and the user gets created, they cannot login via OWA. ... I leave the previously mentioned line out, then user creation works,and the new user can get their ...
(microsoft.public.scripting.vbscript)
• Re: Search doesnt work in Help Center since KDE 3.4
... >> The problem lies with khelpcenter that is called by the susehelp ... >> script. ...
(alt.os.linux.suse)
• Re: Trouble with Microsoft Scripting Example
... CSV-files in a script. ... The problem lies in the Language settings for the ... Once I change the language settings of Windows accordingly, ...
(microsoft.public.windows.server.scripting)
• Re: Using fmincon with ODE
... "Optimization terminated: first-order optimality relative error ... and relative constraint violation less ... I think my problem lies in the passing of variables, ... I have never used Matlabs built-in optimization before, ...
(comp.soft-sys.matlab)