code for bang bang control
Show older comments
I have an optimal control problem with a bounded control : u is between [0,1]. in order to solve it I have use a "bang bang contorl",e.g. I have used the following trick:
V^2=(U+0)*(1-U);
and then created the following code:
syms V U S I R P1 P2 P3 P4;
beta=3/11;
gamma=1/11;
DS= -beta*U*S*I;
DI= beta*U*S*I - gamma*I;
DR= gamma*I
V=sqrt((U+0)*(1-U));
g=0.5*I^2 + 0.5*U^2;
H = g + P1*DS + P2*DI+ P3*DR+P4(V^2-U*(1-U));
However when trying to run this the system gives the following error:
"Array indices must be positive integers or logical values
error in syms/subsref
R_tilde=builtin ('subsref,L_tilde,Idx)
Error in line 9
H = g + P1*DS + P2*DI+ P3*DR+P4(V^2-U*(1-U))
I would like to mention that when removing the part of P4(V^2-U*(1-U)), it runs without Error.
Can someone explain to me how to solve the problem? please advice.
Zofit
Answers (1)
Ameer Hamza
on 14 Jun 2020
Use multiplication operator after P4
P4*(V^2-U*(1-U))
%^
9 Comments
Zofit Allouche
on 15 Jun 2020
Edited: Zofit Allouche
on 15 Jun 2020
Walter Roberson
on 15 Jun 2020
V=sqrt((U+0)*(1-U));
DP4 = -1*diff(H,V);
V is a symbolic expression, not a simple variable. You cannot differentiate a function with respect to an expression (or function)
Ameer Hamza
on 15 Jun 2020
You may apply chain rule here
Therefore, change the line to
DP4 = -1*diff(H,U)*(1/diff(V,U));
Zofit Allouche
on 15 Jun 2020
Edited: Ameer Hamza
on 15 Jun 2020
Ameer Hamza
on 15 Jun 2020
What are you trying to do in these lines?
eq1 = strcat('DS=',char(DS));
eq2 = strcat('DI=',char(DI));
eq3 = strcat('DR=',char(DR));
eq4 = strcat('DP1=',char(DP1));
eq5 = strcat('DP2=',char(DP2));
eq6 = strcat('DP3=',char(DP3));
eq7 = strcat('DP4=',char(DP4));
Can you show your equations in mathematical form?
Zofit Allouche
on 15 Jun 2020
Edited: Zofit Allouche
on 15 Jun 2020
Ameer Hamza
on 15 Jun 2020
dsolve() can take symbolic equations as input.
Also, what I meant that what equation are you trying to solve? It seems that there is some confusion about how to feed those equations to dsolve(). Can you show the actual equations?
Zofit Allouche
on 15 Jun 2020
Edited: Walter Roberson
on 15 Jun 2020
Santanu Bhattacharya
on 30 May 2022
Did you solve this problem?
I also have some similar problem, can we discuss about it?
Categories
Find more on Physics in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!