# Mathematica Boundary Conditions using DSolveValue

I am fairly new here so please forgive me if there is another post with the answer. I have searched but could not find anything that really helped out.

I contacted Mathematica to help with a memory issue when solving a differential equation and they wrote some code for me that does the job however, it is missing the boundary conditions. I then asked them how to insert boundary conditions into the code they provided and they directed me here. Here is the code they had provided:

eqn = (1/((1 + I)*β)^2)*y'''[x] - y'[x] == (Really long equation that is not feasible to type);

(* Find the general solution by setting the rhs to 0. *)

sol1 = DSolveValue[eqn[[1]] == 0, y[x], x]

(sol2 = Map[DSolveValue[eqn[[1]] == #, y[x], x] &, Expand[eqn[[2]]]]);

sol2 = sol2 /. {C[1] -> 0, C[2] -> 0, C[3] -> 0};

y[x_, β_] = sol1 + sol2;


The boundary conditions are

y'[0] == 0, y'[δ] == 0, y[δ] == 0


Here is my question:

With their method of solving the ODE, where would I insert the boundary conditions to obtain my general solution?

I have tried guessing where to put them based on the information given to me in the Wolfram Documentation but I have had no luck. I think my problem is not fully understanding how the Map works.

I am aware that I can have Mathematica solve for each constant using Solve and then insert the each constant back into my solution to obtain the general solution, but I hope there is some way to insert the boundary conditions into their code that would make this process faster.

• Thank you @m_goldberg for editing my post. I just read a link on your profile of how to copy the code and make it look nice. This will be noted for future use. – Carlos Villeda Nov 2 '17 at 21:19
• Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. – bbgodfrey Nov 3 '17 at 14:48

The general solution given in the question is valid only if "Really long equation that is not feasible to type" is independent of y and its derivatives. With this as preface, the general method of applying the boundary conditions is to evaluate the general solution at each of the three boundary conditions, yielding three algebraic equations for the three Cs, which then can be solved. The resulting expressions for the Cs then are inserted into the general solution to obtain the specific solution for the specified boundary conditions. Since the general solution is, evidently, very lengthy, determining the specific solution in this way probably would be slow and require substantial memory.

Fortunately, the boundary conditions in this question are linear and homogeneous, so a simpler approach is feasible. First, solving for sol1 with boundary conditions applied, yields

sol1 = DSolveValue[{eqn[[1]] == 0, y'[0] == 0, y'[δ] == 0, y[δ] == 0}, y[x], x]
(* 0 *)


as expected. Next, apply the boundary conditions to evaluating sol2.

sol2 = Map[DSolveValue[{eqn[[1]] == #, y'[0] == 0, y'[δ] == 0, y[δ] == 0},
y[x], x] &, Expand[eqn[[2]]]];


and this is the desired answer.

To illustrate this with a simple example, consider

eqn = (1/((1 + I)*β)^2)*y'''[x] - y'[x] == a x^3 + b x^2 + c x + d


which DSolve can solve without difficulty.

sol = DSolveValue[{eqn, y'[0] == 0, y'[δ] == 0, y[δ] == 0}, y[x], x] // Simplify;


the result of which is a bit long to reproduce here. Next, solve the example as described above.

sol2 = Map[DSolveValue[{eqn[[1]] == #, y'[0] == 0, y'[δ] == 0, y[δ] == 0},
y[x], x] &, Expand[eqn[[2]]]] // Simplify;

sol == sol2
(* True *)


as desired.

• Thank you very much. This worked great. I almost had it but I did not know the boundary conditions had to be put in both DSolveValue lines. I was only putting them into one. – Carlos Villeda Nov 6 '17 at 3:06