code for bang bang control
Mostrar comentarios más antiguos
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
Respuestas (1)
Ameer Hamza
el 14 de Jun. de 2020
Use multiplication operator after P4
P4*(V^2-U*(1-U))
%^
9 comentarios
Zofit Allouche
el 15 de Jun. de 2020
Editada: Zofit Allouche
el 15 de Jun. de 2020
Walter Roberson
el 15 de Jun. de 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
el 15 de Jun. de 2020
You may apply chain rule here
Therefore, change the line to
DP4 = -1*diff(H,U)*(1/diff(V,U));
Zofit Allouche
el 15 de Jun. de 2020
Editada: Ameer Hamza
el 15 de Jun. de 2020
Ameer Hamza
el 15 de Jun. de 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
el 15 de Jun. de 2020
Editada: Zofit Allouche
el 15 de Jun. de 2020
Ameer Hamza
el 15 de Jun. de 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
el 15 de Jun. de 2020
Editada: Walter Roberson
el 15 de Jun. de 2020
Santanu Bhattacharya
el 30 de Mayo de 2022
Did you solve this problem?
I also have some similar problem, can we discuss about it?
Categorías
Más información sobre Physics en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!