% This function is part of the NMSM Pipeline, see file for full license.
%
% This function uses symbolic polynomial expressions to approximate
% muscle tendon lengths and moment arms
%
% Inputs:
% params.polynomialExpressionMuscleTendonLengths (1 x numberOfMuscles)
% params.polyninomialExpressionMomentArms (1 x numberOfMuscles)
% params.coefficients (1 x numberOfMuscles)
% params.dofsActuated (numberOfCoordinates x numberOfMuscles)
% jointAngles (1 x numberOfMuscles)
%
% (Symbol cell array, Symbol cell array, Number cell array,
% Number cell array) -> (2D Number array, Number cell array)
%
% returns estimated muscle tendon lengths and moment arms
% -----------------------------------------------------------------------
function [newMuscleTendonLengths, newMomentArms, ...
newMuscleTendonVelocities] = calcSurrogateModel(params, jointAngles, ...
jointVelocities)
newMomentArms = zeros(size(jointAngles{1}, 1), ...
length(params.coordinateNames), size(jointAngles, 2));
for i = 1 : size(jointAngles, 2)
% Get A matrix
matrix = PatientSpecificSurrogateModel(jointAngles{i}, jointVelocities{i}, i);
% Caculate new muscle tendon lengths and moment arms
vector = matrix * params.coefficients{i};
newMuscleTendonLengths(:, i) = vector(1 : size(jointAngles{i}, 1));
newMuscleTendonVelocities(:, i) = vector(1 + ...
size(jointAngles{i}, 1) : size(jointAngles{i}, 1) * 2);
index = 2;
for j = 1 : length(params.coordinateNames)
for k = 1 : length(params.surrogateModelLabels{i})
if strcmp(params.coordinateNames(j), params.surrogateModelLabels{i}(k))
newMomentArms(:, j, i) = vector(size(jointAngles{i}, 1) * ...
index + 1 : size(jointAngles{i}, 1) * (index + 1));
index = index + 1;
end
end
end
end
end