Using Matlab (fmincon, ode) to solve an optimal control problem

Поділитися
Вставка
  • Опубліковано 5 вер 2024
  • This is a part of a lecture where I present an example on how to use Matlab to solve a classical optimal control problem.
    It has been recorded in zoom.

КОМЕНТАРІ • 48

  • @rachmawatiw.8753
    @rachmawatiw.8753 Місяць тому +1

    Thx you very much for the video.

    • @rachmawatiw.8753
      @rachmawatiw.8753 Місяць тому

      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?

    • @ahmadhably80
      @ahmadhably80  Місяць тому +1

      Of course

  • @mukhtarsani9871
    @mukhtarsani9871 3 роки тому +3

    Nice video.

  • @rushabhdalal6072
    @rushabhdalal6072 2 роки тому +2

    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

  • @priyaverma3247
    @priyaverma3247 3 роки тому +3

    How to solve optimal control problem with two control parameters, by matlab 2018..
    Could you hwlp me?

  • @40NoNameFound-100-years-ago
    @40NoNameFound-100-years-ago Рік тому +1

    Hello Sir, thank you for such a great video. Is there any way you can share the code? On a google drive for example?

  • @UsmanKhan-dg8kn
    @UsmanKhan-dg8kn 2 роки тому +1

    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

  • @ravikhandelwal2996
    @ravikhandelwal2996 3 роки тому

    Sir please make videos on State space analysis simulation...in simulink... your content is awesome

    • @ahmadhably80
      @ahmadhably80  3 роки тому

      Visit my channel there are a complete course on the subject

  • @santanubhattacharya316
    @santanubhattacharya316 2 роки тому +1

    Thank you Sir. I have one question. What type of control is this?
    Like bang bang or singular or anything else?

  • @aymenbalti5963
    @aymenbalti5963 3 роки тому +1

    great

  • @Sinanmmd
    @Sinanmmd 3 роки тому +1

    Sir, can you please the same for SIR model? I need this code for optimal control in Mathematical Biology

  • @maryyamirfan8620
    @maryyamirfan8620 2 роки тому +2

    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???

  • @arthurmoreno145
    @arthurmoreno145 Рік тому

    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.

  • @ihebkharab
    @ihebkharab Рік тому

    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

  • @user-kp4iy6sr5n
    @user-kp4iy6sr5n 2 роки тому

    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
      @ahmadhably80  2 роки тому

      Please send me the formulation of it?

    • @righteousnasheed7131
      @righteousnasheed7131 2 роки тому

      @@ahmadhably80 Hi Ahmed, how to assign x(0)=x(tf) in fmincon along with other bound and constraints such as xmin

    • @ahmadhably80
      @ahmadhably80  2 роки тому +1

      Please see trajectory optimization

    • @righteousnasheed7131
      @righteousnasheed7131 2 роки тому

      @@ahmadhably80 where? could you please help me with a problem?

  • @marieaimeineza2224
    @marieaimeineza2224 2 роки тому

    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
      @ahmadhably80  2 роки тому

      Send them by email please. They are working on my desktop

  • @lidia1653
    @lidia1653 2 роки тому

    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
      @ahmadhably80  2 роки тому +1

      Could you share your code ?

    • @lidia1653
      @lidia1653 2 роки тому

      @@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

    • @user-zq1mp6si6f
      @user-zq1mp6si6f Рік тому

      انا ليا يا عمو ❤

  • @zeynabjoorsara1457
    @zeynabjoorsara1457 2 роки тому +1

    that's great. Can you share the code with me?

  • @tareqahmad4484
    @tareqahmad4484 2 роки тому

    hi sir, how i can make matlab for discrete cost function ?

    • @ahmadhably80
      @ahmadhably80  2 роки тому

      What do you mean? Sum instead of integral?

    • @melikagolgoon9628
      @melikagolgoon9628 Рік тому

      @@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.

    • @ahmadhably80
      @ahmadhably80  Рік тому

      What is the type of your system. If it is linear try to use lqr. To minimize a riccati equation.

  • @UsmanKhan-dg8kn
    @UsmanKhan-dg8kn 2 роки тому

    Any body here can help me about optimal control stratigies for infectious diseases graphing on MATLAB coding?

  • @user-mh5hr4cb3o
    @user-mh5hr4cb3o 3 роки тому

    can you provide me the code please?

  • @priyaverma3247
    @priyaverma3247 3 роки тому

    Thank you sir,
    But this command is not work in matlab 2018 version

    • @ahmadhably80
      @ahmadhably80  3 роки тому

      Thank you for this comment. Would you explain in which sense it does not work?

    • @nhanNguyen-wo8fy
      @nhanNguyen-wo8fy 3 роки тому +1

      @@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.

    • @user-dr6tj6tz3c
      @user-dr6tj6tz3c 2 роки тому +1

      @@ahmadhably80 great
      Can you healp Me about obtiml control of Nonlinear Systems

    • @user-dr6tj6tz3c
      @user-dr6tj6tz3c 2 роки тому

      And about robust control of linear descriptor system