Getting error in fmincon with below code how to correct it
이전 댓글 표시
% Constants
m = 1; % mass of the rocket (kg)
x_target = 10; % target displacement (m)
t_final = 10; % final time (s)
% Objective function: integral of thrust squared
objective = @(F) integral(@(t) F(t).^2, 0, t_final);
% Initial guess for thrust profile (constant thrust)
%F0 = @(t) 0.0; % Initial guess for thrust profile is a zero vector
F0 = 0.0;
% Constraints
nonlcon = @(F) rocket_constraints(F, t_final, m, x_target);
% Solve optimization problem
options = optimoptions('fmincon', 'Display', 'iter');
F_opt = fmincon(objective, F0, [], [], [], [], [], [], nonlcon, options);
답변 (2개)
You seem to be trying to minimize over a space of functionals, F. You cannot do that with fmincon. The objective must be a function of an unknown parameter vector in
and the initial point x0 must be a vector in 
댓글 수: 4
Charuka
2024년 2월 19일
Matt J
2024년 2월 19일
As well it should. Again, you cannot minimize over function spaces.
Walter Roberson
2024년 2월 19일
fmincon() passes a vector the length of F0 to the objective function.
Your objective function takes that vector and tries to run an integration, with the integration trying to index the vector.
Charuka
2024년 2월 20일
If you define F0 = 0, "fmincon" will use one scalar value as input F to "objective" and "nonlcon". Thus the use of F as a function handle or function doesn't make sense.
댓글 수: 3
Charuka
2024년 2월 19일
The inputs to "objective" and "nonlcon" must be vectors of parameters to be optimized, not functions or function handles.
So you will have to parametrize your function to be integrated and optimize these parameters.
If you don't know how to do that, I suggest you license TOMS software which focusses on solving optimal control problems with MATLAB:
Charuka
2024년 2월 20일
카테고리
도움말 센터 및 File Exchange에서 Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!