Hi Tony,
When using the subs function in MATLAB to substitute symbols in a symbolic expression, the replacement values must be scalar. In your case, A_val is a 61 vector, B_val is a numeric scalar, and C_val is a 21 numeric vector, which is causing the error. To resolve this issue, you need to ensure that the replacement values are scalar. One approach is to replace each element of the vector with the corresponding element in the replacement vector. Here's how you can modify your code to achieve this:
% Define symbolic vectors and scalars
syms A B C
A_val = sym('A_val', [6, 1]);
B_val = sym('B_val');
C_val = sym('C_val', [2, 1]);
% Define the symbolic expression Jacobian_mtx_1
Jacobian_mtx_1 = A + B + C; % Example expression
% Perform substitution with scalar values
for i = 1:numel(A)
Jacobian_mtx_1 = subs(Jacobian_mtx_1, A(i), A_val(i));
end
Jacobian_mtx_1 = subs(Jacobian_mtx_1, B, B_val);
for i = 1:numel(C)
Jacobian_mtx_1 = subs(Jacobian_mtx_1, C(i), C_val(i));
end
So, in the above modified code snippet, I iterate over each element of the symbolic vectors A and C to perform individual substitutions with the corresponding elements in A_val and C_val, respectively. For the scalar symbol B, a direct substitution is made with B_val. By ensuring that the replacement values are scalar or by individually substituting elements of vectors, you can resolve the error and successfully substitute symbols in your symbolic expression. I hope this answers your question.