Using fmincon to optimize Simulink model for optimal trajectory

3 次查看(过去 30 天)
Hello, so i want to search for optimal trajectory (by defining spline) position input to the Simulink Simscape Multibody model to minimize the total force input to the model. However, I encountered the following error in constraint function.
Error using chckxy
The first and second inputs must be of type double or single.
Error in spline (line 72)
[x,y,sizey,endslopes] = chckxy(x,y);
Error in GetStartedWithProblemBasedOptimizeLiveEditorTaskExample>constraintFcn (line 43)
dataStructure.signals(1).values=spline(nTime,locX,dataStructure.time);
Besides form that, when I try to exclude the constraint, the solution of the optimal trajectory is always the same with the initial points. Can anyone help me with the situation? Hereby I attach the folder.

回答(1 个)

Nipun
Nipun 2024-5-30
Hi Joshua,
I understand that you want help with calculating how many hours of data fall within the current hour in MATLAB. Here is a concise approach to solve this:
% Sample data: timestamps as datetime array
timestamps = datetime(2024, 5, 30, randi([0, 23], [100, 1]), randi([0, 59], [100, 1]), randi([0, 59], [100, 1]));
% Current hour
currentHour = hour(datetime('now'));
% Extract hours from timestamps
dataHours = hour(timestamps);
% Count occurrences within the current hour
hoursInCurrentHour = sum(dataHours == currentHour);
disp(hoursInCurrentHour);
Replace timestamps with your actual data.
Hope this helps.
Regards,
Nipun

类别

Help CenterFile Exchange 中查找有关 Optimization 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by