Genetic Algorithm: Find best input combinations that will give global maximum of the output of a non-linear ODE mathematical model using Genetic algorithm
3 views (last 30 days)
Show older comments
The problem is to find the optimum(maximum) value of x3 in range of (-8e-4 to 2e-4) by varying kst,x1,x5 and xo)
x5=5 %Input 2 (Input 2 is a state variable and could vary in range of 4 to 15 while performing optimization)
kst=1 %Input 3 (Input 3 is in terms of rate constant, it could vary from 0.1 to 2)
xo=4 %Input 4 (Input 4 is a state variable and could vary in range of 4 to 10)
x1=1e-7 %Input 1 could vary from 1e-9 to 1e-6
%MATLAB CODE%
% Function file for ODE solution
options = odeset('InitialStep',0.0001,'RelTol',1e-09);
[T,Y]=ode15s(@Scrpt1,[0 60],[9e-13,0],options);
X3= Y(:,2);
plot(T,X3)
%Script file
function rest = Scrpt1(t,X)
x2 = X(1);
x3 = X(2);
%Parameters
if t<15
x1 = 1e-7; %Input 1 could vary from 1e-9 to 1e-6
else
x1 = 0;
end
x5=5; %Input 2 (Input 2 is a state variable and could vary in range of 4 to 15 while performing optimization)
kst=1; %Input 3 (Input 3 is in terms of rate constant, it could vary from 0.1 to 2)
xo=4; %Input 4 (Input 4 is a state variable and could vary in range of 4 to 10)
k1 = 6e7;
km1 = 0.20;
km4 = 0.003;
k3 = 2500.00;
k4 = km4/9;
km3 = km1;
LAP=1.5;
%Differential equations
dx2dt = km1*x3 + km3*LAP - k1*x1*x2 + km4*x3 - k4*x2;
dx3dt = k1*x1*x2 - km1*(x3+x5+xo) - k3*x3*kst;
rest = [dx2dt; dx3dt];
end
How to use Genetic Algorithm for this to solve the mentioned optimization problem of finding maximum value of x3. For which values of x5,kst,xo,x1 we get maximum x3?
My objective function is Maximize(x3).
1 Comment
Torsten
on 8 Jan 2024
Maximum X3 after 60 time units ? Maximum value within the complete interval from 0 to 60 time units ? Maximum mean value in the interval from 0 to 60 time units ?
Answers (1)
VINAYAK LUHA
on 8 Jan 2024
Edited: Torsten
on 8 Jan 2024
Hi Darshna,
I understand that you want to find the maximum value of the variable "x3" using Genetic Algorithm in MATLAB.
Go through the following steps to achieve the above objective.
- Define the objective function that the GA will optimize
- Set Up the GA Options and Constraints
- Run the GA
- Retrieve the Optimal Parameters and Maximum Value of x3
Please note that the GA inherently seeks to minimize the objective function. To find the maximum, we'll need to focus on the negative of the objective function. Additionally, you might need to adjust the GA settings or impose extra constraints to achieve optimal outcomes for your particular scenario.
Below is a sample code for implementing the steps mentioned:
% Define the bounds for the variables x1, x5, kst, xo
lb = [1e-9, 4, 0.1, 4];
ub = [1e-6, 15, 2, 10];
% Set up the GA options
options = optimoptions('ga','PopulationSize', 100,'MaxGenerations', 100,'FunctionTolerance', 1e-6,'Display', 'iter');
% Run the GA
[x_opt, fval] = ga(@objectiveFunction, 4, [], [], [], [], lb, ub, [], options);
% Retrieve the optimal parameters
optimal_x1 = x_opt(1);
optimal_x5 = x_opt(2);
optimal_kst = x_opt(3);
optimal_xo = x_opt(4);
% Maximum value of x3
max_x3 = -fval
% Display the results
fprintf('Optimal x1: %g\n', optimal_x1);
fprintf('Optimal x5: %g\n', optimal_x5);
fprintf('Optimal kst: %g\n', optimal_kst);
fprintf('Optimal xo: %g\n', optimal_xo);
fprintf('Maximum value of x3: %g\n', max_x3);
% Objective Function for the Genetic Algorithm
function x3_max = objectiveFunction(params)
x1 = params(1);
x5 = params(2);
kst = params(3);
xo = params(4);
function rest = Scrpt1(t, X)
x2 = X(1);
x3 = X(2);
if t < 15
x1_val = x1;
else
x1_val = 0;
end
k1 = 6e7;
km1 = 0.20;
km4 = 0.003;
k3 = 2500.00;
k4 = km4 / 9;
km3 = km1;
LAP = 1.5;
dx2dt = km1*x3 + km3*LAP - k1*x1_val*x2 + km4*x3 - k4*x2;
dx3dt = k1*x1_val*x2 - km1*(x3+x5+xo) - k3*x3*kst;
rest = [dx2dt; dx3dt];
end
options = odeset('InitialStep',0.0001,'RelTol',1e-09);
[T,Y] = ode15s(@(t, X) Scrpt1(t, X), [0 60], [9e-13, 0], options);
x3_max = -max(Y(:,2));
end
Additionally, You may refer to the following documentations for more details about the used functions
I hope this clarifies how to apply the Genetic Algorithm in MATLAB to obtain the maximum value of "x3" for your case.
Regards,
Vinayak Luha
0 Comments
See Also
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!