# Question:Help with code for impulsive optimal control problem

## Question:Help with code for impulsive optimal control problem

Maple 2020

Hi,

I am using Maple 2020 to numerically solve/generate numerical plots for my impulsive control problem.

The optimal control problem is:

T is time from0 to T where T is the terminal time

K(t), B(t) and M(t) are state variables

w(t) is a control variable

a(ti) is the impulsive control variable at time ti,

a(ti) \in [0,1] for i=1,2,…,N

ggamma, ttheta, ddelta1, ddelta 2, c1 and c2 are constants

K(T)=M(T)=0 B(T)>0

K'(t)=ggamma*K(t)*w(t)-ttheta*M(t)

B’(t)=ggamma*K(t)+ttheta*M(t)*B(t)

M’(t)=M(t)-ggamma*w(t)

M(ti)=M(ti-)+a(ti)M(ti)*ddelta1

K(ti)=K(ti-)-a(ti)K(ti)*ddelta2

Objective: maximize B(T)-integral from 0 to T of c1*(w(t))^2dt-sum i=1 to N of c2*a(ti)

Here is the code I enter to MAple:

restart;

# Define the constants
ggamma := 1.0;
ttheta := 2.0;
ddelta1 := 0.1;
ddelta2 := 0.2;
c1 := 0.5;
c2 := 0.3;
T := 5.0; # Terminal time

# Define the impulsive changes in M(t)
impulse_changes := proc (t)
local ti_values, imp_values, result;
ti_values := [1.0, 2.0, 3.0]; # Example impulsive time instants
imp_values := [0.2, 0.1, 0.3]; # Corresponding impulsive control values
result := 0;
for i from 1 to nops(ti_values) do
if t = ti_values[i] then
result := result + imp_values[i]*M(ti_values[i])*(ddelta1 - ddelta2);
end if;
end do;
return result;
end proc;

# Define the system of differential equations
diffeqs := {diff(K(t), t) = ggamma*K(t)*w(t) - ttheta*M(t),
diff(B(t), t) = ggamma*K(t) + ttheta*M(t)*B(t),
diff(M(t), t) = M(t) - ggamma*w(t)};

# Define the impulsive controls
impulse_controls := [1.0, 0.5, 0.8]; # Example impulsive control values

# Define the initial values and conditions
initial_values := [K(0) = 0, B(0) = 0, M(0) = 0];

# Define the final conditions
final_conditions := [K(T) = 0, M(T) = 0, B(T) > 0];

# Define the objective function to be maximized
objective := B(T) - int(c1*w(t)^2, t = 0 .. T) - add(c2*impulse_changes(ti), ti = 1.0 .. 3.0);

# Solve the system of differential equations numerically
sol := dsolve({diffeqs, initial_values, final_conditions}, numeric, output = listprocedure);

# Find the optimal control trajectory w(t) using optimization
w_optimal := optimize(objective, numeric, maximize);

# Evaluate the optimal control and state trajectories
optimal_controls := [seq(w_optimal(t), t = 0.0 .. T, 0.1)];
state_trajectories := [sol[2](t), sol[3](t), sol[4](t)];

optimal_controls, state_trajectories;

I am getting the error:

"Error, (in dsolve/numeric/process_input) system must be entered as a set/list of expressions/equations"

as soon I run after the sol:= function.

I would appreciate any help with fixing my code!

Thank you very much!

﻿