Solve for symbolic initial conditions

17 views (last 30 days)
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})
  1 Comment
John
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 );

Sign in to comment.

Accepted Answer

Star Strider
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.
  3 Comments
John
John on 14 Sep 2015
I ended up using collect. Slightly modified example
close all; clc; clear
syms h(t) lambda omega h0 dh0
Dh(t)=diff(h(t),t);
eqs = diff(h(t), t, t) == -lambda*omega*Dh-omega*omega*h(t);
sol=dsolve(eqs, h(0)==h0, Dh(0)==dh0);
pretty(sol)
chk=simplify(diff(sol,t,t)+lambda*omega*diff(sol,t)+omega*omega*sol)
disp('sol for h')
pretty(collect(sol,{h0, dh0}))
disp('sol for dh')
pretty(collect(diff(sol,t),{h0, dh0}))
Star Strider
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.

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!