So I have a linear differential equation which depends on a function f(x) which is piecewise defined, let’s say in regions A, B, C. Due to the form of f(x), it’s easy to find a basis for the solutions in regions A and C, but in B no closed form solutions exist as far as I know. What I want to do is try different initial conditions in A, solve the full equation with NDSolve, and then pull out the results in region C. I know the basis so I’d like to know exactly which linear combination of that basis gives the particular solution in region C.
EDIT: some sample code of an example I threw together
The soln[x] for x>2 should be in the form fSin[x] + gCos[x] and I want to compute the constants f and g. Is there a way to extract this from the NDSolve output?
Hints: \cos 0 = 1 and the derivative of \sin x at x = 0 is also 1. A solution is uniquely determined by a function value and a derivative value at a single value of x.
Thank you, I know how to get the solution if it’s relatively simple like this; I gave a simple example just for sake of example, but is there code that does this numerically for more general cases where there might not be such a straightforward closed-form solution in terms of the boundary conditions?
Hi, I cannot imagine such a case. Do you have an example? I don’t understand what you mean by “simple” or “more general”. The above works for any linear ODE (with suitable coefficients), and the desired form expressed in the question, f \sin x + g \cos x, with f,g constants, implies the ODE is linear.
A slightly more general formula, still for a linear ODE, would be
where a[x] and b[x] are linearly independent solutions. It’s more general in that it does not depend on a[x] and b[x] having 0/1 for both their and their derivatives’ values at a particular point.
This is exactly what I was looking for. By more general I just meant for a basis such that that solving for the coefficients analytically is difficult (for instance if the ODE is of higher order); I somehow completely forgot that this can be reduced into a matrix equation. Thank you!