# Solve for symbolic initial conditions

40 views (last 30 days)
John on 14 Sep 2015
Commented: Star Strider on 14 Sep 2015
A second order mass, damper, spring system can be solved from
syms h(t) m c k h0 dh0 C10 C11
Dh=diff(h(t),t);
eqs = m*diff(h(t), t, t) == -c*Dh-k*h(t);
sol=dsolve(eqs);
h0=subs(sol,t,0);
dh0=subs(diff(sol,t),t,0);
How to rewrite the solution (sol) using the initial condtions (h0, dh0)? I am trying to determine the transition matrix, given h, dh at time 0, find the transition matrix, X, to give h, dh at later time t. I'm looking for a solution like
ic=solve({h0,dh0},{C10, C11})
John on 14 Sep 2015
Based on Stan's answer, change the question to solve first order form, as follows
syms h(t) m c k h0 dh0 C10 C11
Dh(t)=diff(h(t),t);
eqs = m*diff(h(t), t, t) == -c*Dh-k*h(t);
% sol=dsolve(eqs, h(0)==h0, Dh(0)==dh0);
vars = [h(t)];
[eqs1st, vars1st, newVars1st] = reduceDifferentialOrder(eqs, vars);
sol1st=dsolve(eqs1st, h(0)==h0, Dh(0)==dh0 );

Star Strider on 14 Sep 2015
I’m not certain what you’re asking. It’s easy enough to incorporate the initial conditions in your dsolve call, and it’s in the documentation:
syms h(t) m c k h0 dh0 C10 C11
Dh(t)=diff(h(t),t);
eqs = m*diff(h(t), t, t) == -c*Dh-k*h(t);
sol=dsolve(eqs, h(0)==h0, Dh(0)==dh0);
You can also do the integration numerically with ode45, and probably more easily, especially if you use the odeToVectorField function to create the system of first-order ODEs the numeric ODE solvers require. If you do a numeric integration, do not include the initial conditions in your differential equations. Specify them in the ode45 call instead.
Star Strider on 14 Sep 2015
The odeToVectorField function should do what you want. (I use that rather than reduceDifferentialOrder.) I then use that result, sometimes with matlabFunction, to create anonymous functions to use with the numerical ODE solvers, since they will (in most instances) solve for the derivatives as well as the function.