Skip to main content

calcPassiveMomentTrackingCost.m


% This function is part of the NMSM Pipeline, see file for full license.
%
% (Array of number, struct) -> (Array of number)
% returns the cost for all rounds of the MuscleTendonLengthInitialization optimization


function cost = calcPassiveMomentTrackingCost(modeledValues, ...
experimentalData, costTerm)

columnsWithAllZeros = ...
all(experimentalData.passiveData.inverseDynamicsMoments == 0, 3);
inverseDynamicsMoments = ...
experimentalData.passiveData.inverseDynamicsMoments( ...
repmat(~columnsWithAllZeros, 1, 1, 101));
passiveModelMoments = modeledValues.passiveModelMoments( ...
repmat(~columnsWithAllZeros, 1, 1, 101));
errorCenter = valueOrAlternate(costTerm, "errorCenter", 0);
maximumAllowableError = valueOrAlternate(costTerm, "maxAllowableError", 2);

cost = calcTrackingCostArray( ...
passiveModelMoments, ...
inverseDynamicsMoments, ...
errorCenter, ...
maximumAllowableError ...
);
end