It looks like you're using sym/diff
and symfun
s incorrectly. Q(t)
is what is referred to as an arbitrary (help sym/diff
uses the term "abstract" instead) symbolic function, i.e., a function with no definition. Your function's name is Q
(think of it as a function handle) and it is represented by the abstract formula Q(t)
, which just means that it's a function of t
. When you want to take the derivative of an abstract function, pass in the name of the function - in your case, Q
(the online documentation makes this slightly clearer, but not really). When you want evaluate the function use the formula, e.g., Q(0)
, the output of which is a sym
rather than a symfun
.
Here is how I might write the code for your second case:
syms L R C t Q(t)
U = 10*sin(2*t); % No need to wrap integer or exactly-represenable values in sym
dQ = diff(Q,t);
d2Q = diff(dQ,t);
DEQ = L*d2Q + R*dQ + Q/C;
DEQ = subs(DEQ, {L, R, C}, {1, 0, 1/4});
eqn = (U == DEQ);
Q = dsolve(eqn, Q(0) == 0, dQ(0) == 0);
Q = simplify(Q)
which returns
Q =
(5*sin(2*t))/4 - (5*t*cos(2*t))/2
You also forgot to evaluate your initial conditions at zero in the second case so I fixed that too. By the way, in current versions of Matlab you should be using the pure symbolic form for symbolic math (as opposed to strings).