MATLAB: How I explicit one function in terms of another function using symbolic

MATLABsymbolicSymbolic Math Toolbox

syms t T
syms a(t) c0(t) d(t)
I(t) = a(0)*c0(t) + a(2)*c0(t - 2*T) + a(4)*c0(t - 4*T)
Q(t) = a(1)*c0(t - T) + a(3)*c0(t - 3*T) + a(5)*c0(t - 5*T)
s(t) = I(t)*cos(t) - Q(t)*sin(t)
Suppose I wish to express s(t) in terms of I(t) and Q(t). That is, I wish to see
s(t) = I(t)*cos(t) - Q(t)*sin(t)
in the command window. How i do that?
OBS: I don't wanna substitute the awser by I(t) and Q(t). I just wanna explicit I(t) and Q(t) in my expression.
(I know, it's don't seems productive. But in longs expressions, it do).

Best Answer

You define functions I(t) and Q(t) and then use the expression
s(t) = I(t)*cos(t) - Q(t)*sin(t)
and hope to see I(t) and Q(t) in the result even though those have been defined as functions.
In order to do that, you would somehow have to prevent I(t) and Q(t) from executing, and yet not lose their definitions. That involves hacking the way that MATLAB evaluates expressions, which is not going to end well.
You would find it easier to do
syms t T
syms a(t) c0(t) d(t)
syms I_(t) Q(t)
s(t) = I_(t)*cos(t) - Q(t)*sin(t)
I_(t) = a(0)*c0(t) + a(2)*c0(t - 2*T) + a(4)*c0(t - 4*T)
Q(t) = a(1)*c0(t - T) + a(3)*c0(t - 3*T) + a(5)*c0(t - 5*T)
Now if you ask to display s, you would get
I_(t)*cos(t) - Q(t)*sin(t)
and you could then do
subs(s)
to have I_ and Q evaluated to get
cos(t)*(a(0)*c0(t) + a(2)*c0(t - 2*T) + a(4)*c0(t - 4*T)) - sin(t)*(a(1)*c0(t - T) + a(3)*c0(t - 3*T) + a(5)*c0(t - 5*T))
Note the change I had to make to change I(t) to I_(t) . This change is because the symbolic engine treats I specially because inside the symbolic engine, I is used to refer to the imaginary constant sqrt(-1) .
If you ***really** want s to be in terms of I(t) then you can instead use
syms t T
syms a(t) c0(t) d(t)
syms I(t) Q(t)
s(t) = I(t)*cos(t) - Q(t)*sin(t)
I(t) = a(0)*c0(t) + a(2)*c0(t - 2*T) + a(4)*c0(t - 4*T)
Q(t) = a(1)*c0(t - T) + a(3)*c0(t - 3*T) + a(5)*c0(t - 5*T)
s
subs(s, {str2sym('I(t)'), str2sym('Q(t)')}, {I, Q})