code for bang bang control
이전 댓글 표시
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
답변 (1개)
Ameer Hamza
2020년 6월 14일
Use multiplication operator after P4
P4*(V^2-U*(1-U))
%^
댓글 수: 9
Zofit Allouche
2020년 6월 15일
편집: Zofit Allouche
2020년 6월 15일
Walter Roberson
2020년 6월 15일
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
2020년 6월 15일
You may apply chain rule here
Therefore, change the line to
DP4 = -1*diff(H,U)*(1/diff(V,U));
Zofit Allouche
2020년 6월 15일
편집: Ameer Hamza
2020년 6월 15일
Ameer Hamza
2020년 6월 15일
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
2020년 6월 15일
편집: Zofit Allouche
2020년 6월 15일
Ameer Hamza
2020년 6월 15일
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
2020년 6월 15일
편집: Walter Roberson
2020년 6월 15일
Santanu Bhattacharya
2022년 5월 30일
Did you solve this problem?
I also have some similar problem, can we discuss about it?
카테고리
도움말 센터 및 File Exchange에서 Physics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!