Raelynn asked . 2020-12-22

discrete time optimization with non-linear constraints

Hello,
I have an optimization problem to solve with non-linear constraints. It is a control theory based discrete time model (which i feel fules out using fmincon) over a time horizon say N seconds.
I found a few old posts similar to this, but none I felt had clear answers.
I am going nuts trying to find a way to implement it in matlab. Which  Matlab tool would be best suited in this case?
Thanks,
italic EDIT: the system is continuous, but we analyse it in a discrete time domain. Thus, variables have discrete values. There are n_v entities and each of the entity has each parameter described below:
variables: p,v,u; size(p)=size(v)=size(u)=(1,N) vectors
Obj. fn: minimize sum(u(1,:))
constraints:-
Upper and lower bounds like:
p_min<= p(1,:)<= p_max
v_min<= v(1,:)<= v_max
u_min<= u(1,:)<= u_max
linear equalities:
p(n+1)=p(n)+ v(n)t + 0.5u(n)t^2;
v(n+1)=v(n)+u(n)t;
u(n+1)= (s_star / (p1-p2))^2 ; p1 and p2 correspond to entity 1 and 2's p parameter
non linear equalities:
s_star= v1(n) * (v1(n)-v2(n)) ; where v1 and v2 are parameters of entities 1 and 2 respectively at nth instant. * this is the non-linear equality/constraint.
s_star2 = v1(n) * (v1(n)-v1(n-1));
Note: we use either s_star or s_star2 in our code
initial conditions:
p(1)=p_init;
v(1)=vel_init;
end conditions:
p(N)<= p_max;
v(N)=0;
I can give more information if required.

matlab , control system , non-linear constraints

Expert Answer

Neeta Dsouza answered . 2024-05-17 19:47:09

I tried to create an example. Hope this helps.
 
 
 
function [x,f,eflag,outpt] = myModelParamsSolver

xLast = []; % Last place computeall was called
myf = []; % Use for objective at xLast
myc = []; % Use for nonlinear inequality constraint
myceq = []; % Use for nonlinear equality constraint
N = 10;
x0 = rand(1,2+2*N);
fun = @objfun; % the objective function, nested below
cfun = @constr; % the constraint function, nested below
options = optimoptions('fmincon');
lb = zeros(1,2+2*N);
ub = ones(1,2+2*N);
% Call fmincon
[x,f,eflag,outpt] = fmincon(fun,x0,[],[],[],[],lb,ub,cfun,options);

      function y = objfun(x)
          if ~isequal(x,xLast) % Check if computation is necessary
              [myf,myc,myceq] = myDiscreteTimeModel(x);
              xLast = x;
          end
          % Now compute objective function
          y = myf;
      end

      function [c,ceq] = constr(x)
          if ~isequal(x,xLast) % Check if computation is necessary
              [myf,myc,myceq] = myDiscreteTimeModel(x);
              xLast = x;
          end
          % Now compute constraint functions
          c = myc; % In this case, the computation is trivial
          ceq = myceq;
      end

      function [f,c,ceq] = myDiscreteTimeModel(x)
          p = zeros(1,N);
          v = p;
          u = p;
          Ts = 0.01;
          p_max = 100;
          p_init = 10;
          vel_init = 1;

          % initial conditions:
          p(1)=p_init;
          v(1)=vel_init;
          p1 = x(1);
          p2 = x(2);
          v1 = x(3:3+N-1);
          v2 = x(3+N:end);

          for n = 1:N
              t = N*Ts;

              % non linear equalities:
              s_star= v1(n) * (v1(n)-v2(n));
              % where v1 and v2 are parameters of entities 1 and 2 respectively at nth instant.
              % * this is the non-linear equality/constraint.
              %s_star2 = v1(n) * (v1(n)-v1(n-1));
              % Note: we use either s_star or s_star2 in our code

              % linear equalities:
              p(n+1)= p(n)+ v(n)*t + 0.5*u(n)*t^2;
              v(n+1)= v(n)+ u(n)*t;
              u(n+1)= (s_star / (p1-p2))^2 ; % p1 and p2 correspond to entity 1 and 2's p parameter
          end

          % end conditions:
          ceq = v(N);
          c = p(N)-p_max;
          f = sum(u(:));
      end
  end


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.