%% Solve Differential Equations with Conditions
% Solve the first-order differential equation \frac{\textrm{dy}}{\textrm{dt}}=\textrm{ay} with the initial condition y(0)=5.
% Specify the initial condition as the second input to dsolve by using the == operator. Specifying condition eliminates arbitrary constants, such as C1, C2, ..., from the solution.

syms y(t) a
eqn = diff(y,t) == a*y;
cond = y(0) == 5;
ySol(t) = dsolve(eqn,cond)

% Next, solve the second-order differential equation \frac{d^2 y}{{\textrm{dt}}^2 }=a^2 y with the initial conditions y(0)=b and y'(0)=1.
% Specify the second initial condition by assigning diff(y,t) to Dy and then using Dy(0) == 1.

syms y(t) a b
eqn = diff(y,t,2) == a^2*y;
Dy = diff(y,t);
cond = [y(0)==b, Dy(0)==1];
ySol(t) = dsolve(eqn,cond)

% This second-order differential equation has two specified conditions, so constants are eliminated from the solution. In general, to eliminate constants from the solution, the number of conditions must equal the order of the equation.
%
% Copyright 2019 The MathWorks, Inc.