Indexing of symbolic time dependent matrix
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
How do you index a symbolic matrix (or vector in my case) which is defined to be time dependent? Since the homogeneous transform requires a 4x1 vector and the information of the vector is entirely contained in the first 3 elements how do I extract those? The vector in this case is v, where i would want v(1:3) although this commands does not work.
clear; clc; close all;
syms phi(t) theta(t) x(t) y(t) z(t) z0
rz =[cos(phi) -sin(phi) 0 0;
sin(phi) cos(phi) 0 0;
0 0 1 0;
0 0 0 1];
t = [1 0 0 0;
0 1 0 0;
0 0 1 z0;
0 0 0 1];
ry = [cos(theta) 0 sin(theta) 0;
0 1 0 0;
-sin(theta) 0 cos(theta) 0;
0 0 0 1];
h = rz*t*ry;
invH = simplify(inv(h));
v = diff(invH*[x; y; z; 1])
Thanks in advance!
0 Kommentare
Antworten (1)
Walter Roberson
am 4 Okt. 2016
Your v is not a vector, it is a symbolic function that returns a vector of formulas. In order to index it, you need to instantiate it on a particular t value and index the result.
You already assigned a numeric value to t after your syms declared that some things are functions of t. Assigning a numeric value to a symbolic variable almost certainly does not do what you are expecting. Assigning a numeric value to a symbolic variable is like using
A = 1;
B = A * 2;
A = 2;
and expecting that B will have updated to the new value of A -- it doesn't work that way. When you use a symbolic variable in an expression, a copy of the variable at that time is taken, and changes to the variable afterwards have no effect on the expression. You need to subs() in specific values if you want them.
In the meanwhile:
syms T
vv = v(T); %apply function to a specific variable
v1 = vv(1); v2 = vv(2); v3 = vv(3); %you can index the result
v2 would, for example then look like
cos(phi(T))*diff(y(T), T) - sin(phi(T))*diff(x(T), T) - cos(phi(T))*x(T)*diff(phi(T), T) - sin(phi(T))*y(T)*diff(phi(T), T)
0 Kommentare
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!