# Code for solving first-order ode with symbolic initial condition

15 views (last 30 days)
동현 on 25 Nov 2022
Commented: Walter Roberson on 25 Nov 2022
I am very new to MATLAB, and writing MATLAB code for solving the problem #20 of Section 1.1 in Kreyszig (2011).
Problem #20 is as follows:
Exponentialdecay. Subsonicflight. The efficiency of the engines of subsonic airplanes depends on air pressure and is usually maximum near 35,000 ft. Find the air pressure at this height. Physical information. The rate of change is proportional to the pressure. At 18,000 ft it is half its value at sea level.
I wrote the following code for solving the problem, but get a wrong answer.
clear
syms y(t) k
ode = diff(y) == k*y
ode(t) = cond = y(18000) == y(0)/2
cond = ySol(t) = dsolve(ode, cond)
ySol(t) =
0
I got a trivial solution.
How to get a non-trivial solution of this problem?
If I solve the problem with pencil and eraser, the non-trivial solution is .

Torsten on 25 Nov 2022
Edited: Torsten on 25 Nov 2022
syms y(h) k
ode = diff(y) == k*y;
sol_ode_general = dsolve(ode)
sol_ode_general = vars = symvar(sol_ode_general)
vars = eqn1 = subs(sol_ode_general,vars(2),0) == 1.013e5; %pressure in Pa, distance in m
eqn2 = subs(sol_ode_general,vars(2),18000*0.3048) == 1.013e5/2; %pressure in Pa, distance in m
[sol.C_1 sol.k] = solve([eqn1,eqn2],[vars(1),vars(3)]);
sol_ode_specific = subs(sol_ode_general,[vars(1) vars(3)],[sol.C_1,sol.k])
sol_ode_specific = Pressure_at_36000_feet = subs(sol_ode_specific,vars(2),36000*0.3048) % pressure in Pa, distance in m
ans =
25325
Walter Roberson on 25 Nov 2022
dsolve() is only designed to solve for one initial condition per level of derivative. It constructs the general formula solution(t) == f(t) + C and then takes the time of the first initial condition, such as the 0 of y(0), subsitutes that in to get solution(0) == f(0) + C, substitutes in the known value of the initial conditon, getting y0 = f(0) + C and solves for C, and back-substitutes that to get solution(t) = f(t) + specific_constant . Then when the second initial condition y(18000) is hit, there is no remaining constant to solve for in solution(t) = f(t) + specific_constant -- at least not a constant at the same level, and if y0 happened to involve multiple unknown variables, the second initial condition would not know which one it is intended to solve for.
dsolve() is not designed to specifically look for periodic solutions. If you have unknowns in the equations whose value is to be determined by the multiple initial conditions, then solve for one initial condition using dsolve() and after that step through one initial condition at a time solve() for each appropriate variable.