code for bang bang control
Ältere Kommentare anzeigen
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
Antworten (1)
Ameer Hamza
am 14 Jun. 2020
Use multiplication operator after P4
P4*(V^2-U*(1-U))
%^
9 Kommentare
Zofit Allouche
am 15 Jun. 2020
Bearbeitet: Zofit Allouche
am 15 Jun. 2020
Walter Roberson
am 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
am 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
am 15 Jun. 2020
Bearbeitet: Ameer Hamza
am 15 Jun. 2020
Ameer Hamza
am 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
am 15 Jun. 2020
Bearbeitet: Zofit Allouche
am 15 Jun. 2020
Ameer Hamza
am 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
am 15 Jun. 2020
Bearbeitet: Walter Roberson
am 15 Jun. 2020
Santanu Bhattacharya
am 30 Mai 2022
Did you solve this problem?
I also have some similar problem, can we discuss about it?
Kategorien
Mehr zu Physics finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!