Solve for symbolic initial conditions

17 次查看(过去 30 天)
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 个评论
John
John 2015-9-14
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
Star Strider 2015-9-14
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 个评论
John
John 2015-9-14
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 2015-9-14
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Equation Solving 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by