Sir can you help me in making graph on MATLAB. Actually I have done my all part or numerical but still facing problem in MATLAB coding of optimal control strategies for infectious disease
How to find parameters a and b such that the sum of quadratic errors e=sum_i((ym_i-y(tm_i))^2) between measurements ym and model output y is minimal using optimizers such as fminunc and ODE. The model reads xt=[0 1; a b]*x; y=x; tm ym 0 1.0000 0.5000 0.6482 1.0000 -0.1047 1.5000 -0.6897
Hello Ahmad, Can you help me with problem ? I didn't understand why you didn't use the final state in the code even though you declared x1 as a global variable.
Hi sir, thank you for this helpful video, I have an issue with coding the same principle but, I have a two variable function in an SI model and I want to minimize the infections by adding the travel restriction function u , and can be treated as a signal or so as you did in the video, could you please help me? I have errors on the coding part that I do not know how to fix. Thank you in advance
Thank you for sharing your knowledge! Could you please help me understand your "way of a contraction of U"? I used your example to find the optimal control for a simple SIR model with a control variable from 0 to 1. And I expected to obtain the graphic for U from 0 to some optimal value U. However, in the results, I got that the initial point of the control was not equal to zero but greater to zero. Could you please help understand why the control is not equal to zero at the initial point?
@@ahmadhably80 Thank you for your reply! I did it. Graph U already has the correct results. The graph is not very smooth, but the values are correct. I will attach the code below if you are still interested in it. How do you think is it possible to transform this problem into a multi-objective problem? Ex. to minimize the cost integral (objective function for the integral of the control), and simultaneously to maximize the second objective function, say, to maximize the number of recovered. global T N I0 np S0 R0 Y0 x0 T=30; N=10; I0=1; np=169; S0=np-I0; R0=0; Y0=0; x0=[S0;I0;R0;Y0]; lesu_init=zeros(1,N); u_out = fmincon(@cost3, lesu_init, [],[],[],[],zeros(1,N),ones(1,N),@nonlcon); [t,x]=ode45(@my_ode2, [0 T], x0, [], u_out); figure (1) umin2=[u_out u_out(:,end)]; t2=(0:T/N:T); ui=smooth(t2,umin2) ; stairs(0:T/N:T, umin2,'r'); hold on plot(t2, ui,'b'); xlabel('temps') legend('u optimal'); hold off figure (2) plot(t,x(:,1:3)); xlabel('temps') legend('x1','x2','x3'); figure (3) plot(t,x(:,4)); xlabel('temps') legend('x4'); function xdot=my_ode2(t,x,lesu) lamda = 0.005; gamma = 0.04; q=1.5; u=udet2(t, lesu); xdot=zeros(4,1); xdot(1)=- lamda *x(1)*x(2); %S xdot(2)=lamda * x(1)*x(2) - gamma *x(2)-u*x(2); xdot(3)=gamma * x(2)+u*x(2); xdot(4)=q*u*u; end % U function vector=udet2(t, lesu) global T N a=N*t/T; if a==0 vector=lesu(:,1); else vector=lesu(:, abs(ceil(a))); end end %Cost function we want to minimize x(2)+int(q*u^2)dt function J2=cost3(lesu) global T x0 u_out [t,x]=ode45(@my_ode2,[0,T],x0,[],lesu); J21=(x(end,2)); J22=(x(end,4)); J2=J21+J22; end function [c,ceq]=nonlcon(lesu) global T x0 [t,x]=ode45(@my_ode2,[0,T],x0,[],lesu); c=[]; ceq=[]; end
Thx for this video, it really helpfully but i tried to run these codes in MATLAB 2018a unfortunately they are not working. they keep giving errors like not enough inputs argument. need your help!!!!!!!!
@@ahmadhably80 Yes. My objective function is the derivative of the Lyapunov function and I want to find the optimal u that minimizes Vdot. I don't have an integral in my objective function in this case. Should I add an integral with some time span? Because, after all, I want to see how the optimal u changes as the state goes through that time span.
Thank you sir! Can you please show another example about solving the optimal control problem with the final time tf free which is also called the linear quadratic minimum-time problem?
@@ahmadhably80 Professor I laugh so hard at your answer. Your answer made my day. That answer is very coder. =)))) You know, like this guy in Vietnam control engineering student think about Matlab much like an App not a programming language. I also thought "What the hell why this guy think this may not work on Matlab2018a". Just like you. But I quickly understand why.
Nice video.
Hello Sir, thank you for such a great video. Is there any way you can share the code? On a google drive for example?
How to solve optimal control problem with two control parameters, by matlab 2018..
Could you hwlp me?
Sir can you help me in making graph on MATLAB. Actually I have done my all part or numerical but still facing problem in MATLAB coding of optimal control strategies for infectious disease
How to find parameters a and b such that the sum of quadratic errors e=sum_i((ym_i-y(tm_i))^2) between measurements ym and model output y is minimal using optimizers such as fminunc and ODE.
The model reads
xt=[0 1; a b]*x;
y=x;
tm ym
0 1.0000
0.5000 0.6482
1.0000 -0.1047
1.5000 -0.6897
Sir, can you please the same for SIR model? I need this code for optimal control in Mathematical Biology
Can you give your model
Thank you Sir. I have one question. What type of control is this?
Like bang bang or singular or anything else?
optimal control type
Thx you very much for the video.
My research is also in the area of optimal control, mostly in Industrial Engineering; and love MATLAB so much. May I contact you someday to discuss?
Of course
Hello Ahmad, Can you help me with problem ? I didn't understand why you didn't use the final state in the code even though you declared x1 as a global variable.
what do you mean by the final state?
Hi sir, thank you for this helpful video, I have an issue with coding the same principle but, I have a two variable function in an SI model and I want to minimize the infections by adding the travel restriction function u , and can be treated as a signal or so as you did in the video, could you please help me? I have errors on the coding part that I do not know how to fix.
Thank you in advance
what is the type of your input?
Hi sir..
My MATLAB code show alot of errors then i clear all ...but still my code bot running .. can you please help in making my code???
Please share it
@@ahmadhably80 in comments???
By email
Thank you for sharing your knowledge!
Could you please help me understand your "way of a contraction of U"?
I used your example to find the optimal control for a simple SIR model with a control variable from 0 to 1. And I expected to obtain the graphic for U from 0 to some optimal value U. However, in the results, I got that the initial point of the control was not equal to zero but greater to zero.
Could you please help understand why the control is not equal to zero at the initial point?
Could you share your code ?
@@ahmadhably80 Thank you for your reply! I did it. Graph U already has the correct results. The graph is not very smooth, but the values are correct. I will attach the code below if you are still interested in it.
How do you think is it possible to transform this problem into a multi-objective problem? Ex. to minimize the cost integral (objective function for the integral of the control), and simultaneously to maximize the second objective function, say, to maximize the number of recovered.
global T N I0 np S0 R0 Y0 x0
T=30; N=10; I0=1; np=169; S0=np-I0; R0=0; Y0=0; x0=[S0;I0;R0;Y0]; lesu_init=zeros(1,N);
u_out = fmincon(@cost3, lesu_init, [],[],[],[],zeros(1,N),ones(1,N),@nonlcon); [t,x]=ode45(@my_ode2, [0 T], x0, [], u_out);
figure (1)
umin2=[u_out u_out(:,end)]; t2=(0:T/N:T); ui=smooth(t2,umin2) ; stairs(0:T/N:T, umin2,'r'); hold on
plot(t2, ui,'b'); xlabel('temps')
legend('u optimal'); hold off
figure (2)
plot(t,x(:,1:3)); xlabel('temps')
legend('x1','x2','x3');
figure (3)
plot(t,x(:,4)); xlabel('temps')
legend('x4');
function xdot=my_ode2(t,x,lesu)
lamda = 0.005; gamma = 0.04; q=1.5; u=udet2(t, lesu); xdot=zeros(4,1); xdot(1)=- lamda *x(1)*x(2); %S
xdot(2)=lamda * x(1)*x(2) - gamma *x(2)-u*x(2); xdot(3)=gamma * x(2)+u*x(2); xdot(4)=q*u*u;
end
% U
function vector=udet2(t, lesu)
global T N
a=N*t/T;
if a==0
vector=lesu(:,1);
else
vector=lesu(:, abs(ceil(a)));
end
end
%Cost function we want to minimize x(2)+int(q*u^2)dt
function J2=cost3(lesu)
global T x0 u_out
[t,x]=ode45(@my_ode2,[0,T],x0,[],lesu); J21=(x(end,2)); J22=(x(end,4)); J2=J21+J22;
end
function [c,ceq]=nonlcon(lesu)
global T x0
[t,x]=ode45(@my_ode2,[0,T],x0,[],lesu); c=[]; ceq=[];
end
انا ليا يا عمو ❤
can you provide me the code please?
Thx for this video, it really helpfully but i tried to run these codes in MATLAB 2018a unfortunately they are not working. they keep giving errors like not enough inputs argument. need your help!!!!!!!!
Send them by email please. They are working on my desktop
hi sir, how i can make matlab for discrete cost function ?
What do you mean? Sum instead of integral?
@@ahmadhably80 Yes. My objective function is the derivative of the Lyapunov function and I want to find the optimal u that minimizes Vdot. I don't have an integral in my objective function in this case. Should I add an integral with some time span? Because, after all, I want to see how the optimal u changes as the state goes through that time span.
What is the type of your system. If it is linear try to use lqr. To minimize a riccati equation.
great
Any body here can help me about optimal control stratigies for infectious diseases graphing on MATLAB coding?
What do you mean by graphing?
Thank you sir! Can you please show another example about solving the optimal control problem with the final time tf free which is also called the linear quadratic minimum-time problem?
Please send me the formulation of it?
@@ahmadhably80 Hi Ahmed, how to assign x(0)=x(tf) in fmincon along with other bound and constraints such as xmin
Please see trajectory optimization
@@ahmadhably80 where? could you please help me with a problem?
Sir please make videos on State space analysis simulation...in simulink... your content is awesome
Visit my channel there are a complete course on the subject
that's great. Can you share the code with me?
no I cannot :-)
Thank you sir,
But this command is not work in matlab 2018 version
Thank you for this comment. Would you explain in which sense it does not work?
@@ahmadhably80 Professor I laugh so hard at your answer. Your answer made my day.
That answer is very coder. =))))
You know, like this guy in Vietnam control engineering student think about Matlab much like an App not a programming language.
I also thought "What the hell why this guy think this may not work on Matlab2018a". Just like you. But I quickly understand why.
@@ahmadhably80 great
Can you healp Me about obtiml control of Nonlinear Systems
And about robust control of linear descriptor system