MATLAB: Replace x with x(t) in a symbolic matrix

differentialdifferential equationslinear algebrasymbolic computationsymbolic matrix

Hello,
I have a 3×3 symbolic matrix T1. I want to replace theta1 with theta1(t), theta2 with theta2(t) in my matrix. I tried using the subs function like so
syms theta1 theta2 theta3
AT1 = subs(T1, {theta1, theta2, theta3},...
{theta1(t), theta2(t), theta3(t)})
%--------------- My T1 is-----------
[ cos(theta1 + theta2 + theta3), sin(theta1 + theta2 + theta3), 0, 8*cos(theta1 + theta2 + theta3) + 5*cos(theta1 + theta2) + 10*cos(theta1)]
[ -sin(theta1 + theta2 + theta3), cos(theta1 + theta2 + theta3), 0, - 8*sin(theta1 + theta2 + theta3) - 5*sin(theta1 + theta2) - 10*sin(theta1)]
[ 0, 0, 1, 0]
[ 0, 0, 0, 1]
but matlab expects an arithmetic expression as the input function in "subs", hence throws an error.
A workaround I thought of, was calling elements individually and converting them, but however I try an error shows up when I use brackets. By which I mean 'theta1' can be replaced by 'theta4' but not 'theta4(t)'.
In the end I need to differentiate T1, so theta has to be theta(t) for "diff" function to work properly
Please let me know how I can solve this issue.
PS: It is also fine if there is some way I can call elements of the matrix below, but I don't think it is possible
>> T10
T10(t) =
[ cos(theta1(t)), sin(theta1(t)), 0, 10*cos(theta1(t))]
[ -sin(theta1(t)), cos(theta1(t)), 0, -10*sin(theta1(t))]
[ 0, 0, 1, 0]
[ 0, 0, 0, 1]
Thanks,
Venkatesh.

Best Answer

syms theta1 theta2 theta3
T = [ cos(theta1 + theta2 + theta3), sin(theta1 + theta2 + theta3), 0, 8*cos(theta1 + theta2 + theta3) + 5*cos(theta1 + theta2) + 10*cos(theta1)
-sin(theta1 + theta2 + theta3), cos(theta1 + theta2 + theta3), 0, - 8*sin(theta1 + theta2 + theta3) - 5*sin(theta1 + theta2) - 10*sin(theta1)
0, 0, 1, 0
0, 0, 0, 1];
syms theta4(t) theta5(t) theta6(t)
temp = subs(T, {theta1, theta2, theta3}, {theta4, theta5, theta6});
syms theta1(t) theta2(t) theta3(t)
AT1 = subs(temp, {theta4, theta5, theta6}, {theta1, theta2, theta3});
"It is also fine if there is some way I can call elements of the matrix below,"
T10(t) =
[ cos(theta1(t)), sin(theta1(t)), 0, 10*cos(theta1(t))]
That is not a matrix: it is a symbolic function that returns a matrix. You cannot access individual elements of the function through normal indexing. You can, however, use formula(T10) which will return an array result that is not a function, and then you can index the array result.