dsolve unable to convert to type 'branch'
Mostra commenti meno recenti
I'm trying to find the optimal control of a system of differential equations subject to some cost function. The system of differential equations is given below:

The cost function is
The control is bang-bang (see below), and the function g is described below. The final time T is left free but we assume for the sake of example that
. Model parameters include
and γ.
(which appears above) and
(which appears below) are simply parameters denoting cost. The differential equations pertaining to the adjoint vector are


Where
is the adjoint vector. The optimal control u is bang-bang and such that
for
and
otherwise. Furthermore, the function g adjusts the cost associated with
and
. That is, for
then
, and
for
.
is simply a scalar. Since I am trying to find the optimal control, this requires that the terminal (or end) conditions of the adjoint variables be
. The initial conditions of the state variables are
and
. The end conditions of the state variables are left free. I tried solving this system with the following script (adapted from another optimal control question on this site):
clear all;
% helpful variables
beta = 2;
alpha = 0.1;
gamma = 0.1;
M = 20;
IHat = 40;
T = 5;
k1 = 10;
k2 = 20;
c = 2;
N = 100;
% State equations
syms x1 x2 x3 p1 p2 p3 u;
Dx1 = -beta*x1*(x2+x3)/N + M*(x2/(x1+x2))*(p1 > (p2 + k1*(x1+x2)/x2)) + alpha*x3;
Dx2 = beta*x1*(x2+x3)/N - gamma*x2 - M*(x2/(x1+x2))*(p1 > (p2 + k1*(x1+x2)/x2));
Dx3 = gamma*x2 - alpha*x3;
% Cost function inside the integral
syms g;
g = -(k1*u + ((x2+x3) > IHat)*c*k2*(x2+x3) + ((x2 + x3) <= IHat)*k2*(x2+x3));
% Hamiltonian
syms p1 p2 p3 H;
H = g + p1*Dx1 + p2*Dx2 + p3*Dx3;
% Costate equations
Dp1 = -diff(H,x1);
Dp2 = -diff(H,x2);
Dp3 = -diff(H,x3);
% convert symbolic objects to strings for using 'dsolve'
eq1 = strcat('Dx1=',char(Dx1));
eq2 = strcat('Dx2=',char(Dx2));
eq3 = strcat('Dx3=',char(Dx3));
eq4 = strcat('Dp1=',char(Dp1));
eq5 = strcat('Dp2=',char(Dp2));
eq6 = strcat('Dp3=',char(Dp3));
sol_h = dsolve(eq1,eq2,eq3,eq4,eq5,eq6);
% use boundary conditions to determine the coefficients
% x1(0)=N-sum(I0); x2(0)=I0(1); x3(0)=I0(2);
% p1(T) = 0; p2(T) = 0; p3(T) = 0
conA1 = 'x1(0) = 90';
conA2 = 'x2(0) = 5';
conA3 = 'x3(0) = 5';
conA4 = 'p1(5) = 0';
conA5 = 'p2(5) = 0';
conA6 = 'p3(5) = 0';
sol_a = dsolve(eq1,eq2,eq3,eq4,eq5,eq6,conA1,conA2,conA3,conA4,conA5,conA6);
But I received the following error (when evaluating sol_h):
> In dsolve (line 121)
Error using symengine
Unable to convert to type 'branch'.
Error in mupadengine/evalin_internal (line 113)
res = mupadmex(statement,output_type{:});
Error in dsolve>mupadDsolve (line 327)
sys = [sys_sym reshape(evalin_internal(symengine, sys_str), 1, [])];
Error in dsolve (line 183)
sol = mupadDsolve(args, options);
I was unable to find another question with the same issue of conversion to type 'branch' so I figured I'd make a new question addressing this. Any help would be greatly appreciated.
1 Commento
Walter Roberson
il 24 Lug 2020
Is there anything we can assume about the values? For example can we assume that the functions are completely real-valued ?
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Numeric Solvers in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!