MATLAB Answers

How to solve differential equations with parameters using fmincon to find out optimized parameters

98 views (last 30 days)
kkng
kkng on 18 Jun 2014
Commented: kkng on 19 Jun 2014
Hello, I need to find out the optimized two parameter(a and b) to make minimum of (f2+f1-0.576). What I have is the differential equations of f1,f2,and f3.
for example, f1'=3*a/b*f2*f1+16*(f3-f1) f2'=-3*a/b*f2*f1+(f3-f1) f3'= 5*a/b*f1+(f2+f3) f1(0)=f2(0)=f3(0)=1 and f2(1)+f1(1)=0.576 for 0<-x<-1. The ranges of parameters are 0<-a<-10 and 100<-b<-1000.
And I want to use fmincon to optimize a and b to make minimum of (f2(1)+f1(1)-0.576). I can solve the differential equations with the fixed a and b. But I don't know how to find out the optimized a and b. My fmincon equation is, [x,f]=fmincon (@myfun,...)
F=myfun (x,a,b) F=f2(1)+f1(1)-0.576
In F equation, there is no a or b, so I can not set the initial,Ub, or Lb for a and b in fmincon. Actually, I don't know how to solve the differential equations with ode45 without a and b now. Can anyone help me to solve the equation? Thank you in advance.

Accepted Answer

Jason Nicholson
Jason Nicholson on 19 Jun 2014
Edited: Jason Nicholson on 19 Jun 2014
You need two functions:
  1. Function to compute derivative. Mine is called "derivative."
  2. Function to compute objective function. Mine is called "objectiveFunction."
Once you have the objective function, call fmincon. I do this in runOptimization. Note that
a = 3.2737
b = 3.2530
runOptimization.m
ab0 = [1; 1]; % initial guess
A = [ 1 0; % a<100
-1 0; % a>0
0 1; % b<22
0 -1];% b>0
b = [100*(1-eps); % a<100
0-eps; % a>0
22*(1-eps); % b<22
0-eps]; % b>0
ab = fmincon(@objectiveFunction, ab0, A, b);
a = ab(1);
b = ab(2);
derivative.m
function df = derivative(x, f, ab)
a = ab(1);
b = ab(2);
df = zeros(3,1);
df(1)=3*a/b*f(2)*f(1)+16*(f(3)-f(1));
df(2)=-3*a/b*f(2)*f(1)+(f(3)-f(1));
df(3)= 5*a/b*f(1)+(f(2)+f(3));
end % end function, derivative
objectiveFunction.m
function cost = objectiveFunction(ab)
f0 = [1;1;1];
[~, f] = ode113(@(t,f) derivative(t, f, ab), [0 1], f0);
cost = f(2, end) + f(1, end) - 0.576;
end % end function, objectiveFunction
  3 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by