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

1 Ansicht (letzte 30 Tage)
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 !! :)

Akzeptierte Antwort

Mischa Kim
Mischa Kim am 18 Feb. 2015
Bearbeitet: Mischa Kim am 18 Feb. 2015
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 Kommentare
Mischa Kim
Mischa Kim am 20 Feb. 2015
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))

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by