Re: Using fmincon with ODE
- From: "Tais Hansen" <taisclaridge@xxxxxxxxx>
- Date: Wed, 23 Sep 2009 16:32:04 +0000 (UTC)
Thanks for the reply...
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.
.
- Follow-Ups:
- Re: Using fmincon with ODE
- From: Alan Weiss
- Re: Using fmincon with ODE
- References:
- Using fmincon with ODE
- From: Tais Laridge
- Re: Using fmincon with ODE
- From: Alan Weiss
- Using fmincon with ODE
- Prev by Date: multi-variate linear regression with interactions
- Next by Date: Re: left/right preconditionner
- Previous by thread: Re: Using fmincon with ODE
- Next by thread: Re: Using fmincon with ODE
- Index(es):
Relevant Pages
|