Matlab symbolic variables depending on time "t" and call of symbolic vector elements

Hi everybody :)
I have the following problem :
syms t x(t) y(t) z(t) theta1(t) theta2(t)
Y = [0 cos(theta1);1 sin(theta2)] * [x y]'
now the first problem is that when I call the first element of the vector V with the command "V(1)" I does't become the first element of the vecotr V but rather the hole vector with 1 instead of t, I mean :
cos(theta1(1))*conj(y(1))
conj(x(1)) + conj(y(1))*sin(theta2(1))
but what I want is this :
cos(theta1(t))*conj(y(t))
I mean only the first element which depends on t that I defined at the first of the script .
now the second little problem is that I want to give to theta1 and the other symbolic variables a start value but when I write this :
theta1(0) = 5 I become an error :
Error using symfun>validateArgNames (line 165) Second input must be a scalar or vector of unique symbolic variables.
Error in symfun (line 42) y.vars = validateArgNames(inputs);
Error in sym/subsasgn (line 1640) C = symfun(B,[inds{:}]);
Error in test (line 9) theta1(0)=5
thx for helping me !! :)

 Accepted Answer

Mohamed, to your first question: use instead
Y = [0 cos(theta1);1 sin(theta2)] * [x; y] % note the last semi-colon
Y =
cos(theta1(t))*y(t)
x(t) + sin(theta2(t))*y(t)
At that point you can start substituting values. E.g.
subs(Y,{theta1},{0})
ans =
y(t)
x(t) + sin(theta2(t))*y(t)
Does that help?

5 Comments

Thx Kim for your answer but actually I don't want to substitute elements from the vector but rather call its elements.
Could you give an example of what exactly you want to do and what the result is supposed to look like?
when I use a normal vector for example :
B=[5;6]
calling the first element of the vector would look like : B(1) so I'll get the result 5 and my problem is that when I use the symbolic tool for example
syms t theta(t) x(t)
A=[cos(theta) x]
using the command A(1) for calling the first element of the vector A like what I done by B will show the following result
A=
cos(theta(1))
x(1)
But what I want is to get the first element :
cos(theta(t))
so I can use it independently of the vector A ...so my question is how can I call the first element of a vector with symbolic elements that depends on time.
thx :)
OK. Yes you can, but it is a bit cumbersome. The challenge is that it is not possible to create an array of symfuns, as far as I am aware.
Y = [0 cos(theta1);1 sin(theta2)] * [x; y];
Y = Y(t); % convert symfun to sym...
Y1fun = symfun(Y(1),t); % ...and convert back to symfun
Y1fun(3)
ans =
y(3)*cos(theta1(3))

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!