Replace x with x(t) in a symbolic matrix
조회 수: 2 (최근 30일)
이전 댓글 표시
Hello,
I have a 3x3 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.
댓글 수: 0
채택된 답변
Walter Roberson
2019년 8월 12일
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.
댓글 수: 3
Walter Roberson
2019년 8월 12일
If you are looking at seperating out those things, then I recommend that you have a look at odeFunction() and the workflow shown in the first example, including odeToVectorField
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!