Using fmincon to optimize Simulink model for optimal trajectory

조회 수: 4 (최근 30일)
Joshua Levin Kurniawan
Joshua Levin Kurniawan 2024년 5월 10일
답변: Nipun 2024년 5월 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에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by