1
$\begingroup$

I'm trying to solve the following problem:

enter image description here

I already know the answer is $y(x) = x^2$, but how could I ask Mathematica to solve this for me?

DSolve[{y'[x] == c x, y[1] == 1 && y[0] == 0}, y[x], x]

Got:

DSolve::bvnul: For some branches of the general solution, the given boundary conditions lead to an empty solution.: For some branches of the general solution, the given boundary conditions lead to an empty solution.

$\endgroup$
2
  • 4
    $\begingroup$ You have first order ode. So there is only ONE constant of integration. But you have two equations to solve for the one constant of integration. When using the first equation you get different answer than when you use the second equation. Hence no unique solution exist. When solving an ode, the number of initial/boundary conditions should not be more than the order of the ode. $\endgroup$
    – Nasser
    Jan 10, 2022 at 5:39
  • $\begingroup$ @Nasser but in this case, $y(x)=x^2$ is the unique solution, isn't it...? $\endgroup$ Jan 10, 2022 at 7:39

5 Answers 5

5
$\begingroup$

Is this acceptable?

sol = DSolveValue[{y'[x] == c x, y[0] == 0}, y[x], x]
sol /. Solve[(sol /. x -> 1) == 1, c]

{x^2}

$\endgroup$
5
$\begingroup$

I think there is some confusion here on terminology.

You said in the title of your question solve with constant. So $c$ in your ode is a constant which can't be changed. So the solution should be valid for any value of $c$. The ode is

\begin{align*} y^{\prime}\left( x\right) & =cx\\ y\left( 0\right) & =0\\ y\left( 1\right) & =1 \end{align*}

The solution is $$ y=c\frac{x^{2}}{2}+C_{1}% $$ where $C_{1}$ is constant of integration. Substituting the first BC in the above general solution gives the equation \begin{equation} 0=C_{1}\tag{1} \end{equation} Substituting the second BC gives the equation \begin{equation} 1=\frac{c}{2}+C_{1}\tag{2} \end{equation} Since we must have the same constant of integration, then we see only when $c=2$ this will happen. And in this case the solution above becomes $y=x^{2}$. But $c$ is constant which we do not know its value. We are not free to set $c$ to any value we want. Otherwise, the ode you are solving now is \begin{align*} y^{\prime}\left( x\right) & =2x\\ y\left( 0\right) & =0\\ y\left( 1\right) & =1 \end{align*} Now, if you had said that you wanted to solve an eigenvalue boundary value problem given by \begin{align*} y^{\prime}\left( x\right) & =\lambda x\\ y\left( 0\right) & =0\\ y\left( 1\right) & =1 \end{align*} Now it it a different problem. The $\lambda$ above is not a constant any more. The system now have an extra degree of freedom we can modify to find a solution, which is $\lambda$. i.e. we can try to find $\lambda$ such that the solution fits to the boundary conditions. For $\lambda=2$ a solution exist which satisfies both ends and is given by $y=x^{2}$.

The solution posted earlier treated this problem as an eigenvalue ode where one is free to change $c$. Which is correct if it was such a problem, but you said that $c$ was constant not an eigenvalue.

This is why Mathematica did not solve it.

$\endgroup$
4
$\begingroup$

If $y' = c x$, then we can isolate $c$ on one side of the equation and differentiate to obtain a higher-order ODE that doesn't depend on $c$ at all: $$ \frac{d}{dx}\left(\frac{y'}{x}\right) = 0 \quad \Rightarrow \frac{y''}{x} - \frac{y'}{x^2} = 0 $$ Mathematica can solve this ODE (and the associated initial conditions) readily:

DSolve[{y''[x]/x - y'[x]/x^2 == 0, y[0] == 0, y[1] == 1}, y[x], x]
(* {{y[x] -> x^2}} *)

If you ever need to apply this method to a more complicated ODE, you can automate the process of eliminating $c$ as follows:

eqn = (y'[x] == c x);
higherordereqn = D[eqn, x];
crule = Solve[eqn, c];
neweqn = higherordereqn /. First[crule]

(* y''[x] == y'[x]/x *)
$\endgroup$
4
$\begingroup$

Here's a different way to solve the problem. We tell DSolve that c has to be solved for as well by turning it into a constant function:

DSolve[
  {y'[x] == c[x] x, c'[x] == 0, y[1] == 1 && y[0] == 0},
  {y[x], c[x]},
  x
]

{{c[x] -> 2, y[x] -> x^2}}

It's a nifty little trick that works from time to time.

$\endgroup$
4
$\begingroup$

DSolve is not set up to solve BVPs with parameters, even though theoretically it could.

Below is a modification of the Todd-Gayley trick used in Accessing Reduce from DSolve that hacks the algorithm at the point Solve is used to solve the BCs for the integration constant(s):

Internal`InheritedBlock[{Solve}, Unprotect[Solve];
 Solve[eq_, v_, opts___] /; ! TrueQ[$in] := Block[{$in = True, $res1, $res2},
   If[MemberQ[v, _C],(* assumes generated parameters are C[k] *)
    
    Solve[eq, Append[v, c], opts],
    Solve[eq, v, opts]
    ]
   ];
 Protect[Solve];
 DSolve[{y'[x] == c x, y[1] == 1 && y[0] == 0}, y[x], x]
 ]

(*  {{y[x] -> x^2}}  *)

We could wrap it up in a superfunction:

parametricBVP // Options = Options@DSolve;
parametricBVP[sys_, y_, x_, p_, opts : OptionsPattern[]] := 
  Internal`InheritedBlock[{Solve}, Unprotect[Solve];
   Solve[eq_, v_, rest___] /; ! TrueQ[$in] := Block[{$in = True, $res1, $res2},
     If[MemberQ[v, _C],(* assumes generated parameters are C[k] *)
      Solve[eq, Flatten@{v, p}, rest],
      Solve[eq, v, rest]
      ]
     ];
   Protect[Solve];
   DSolve[sys, y, x, opts]
   ];

Example:

parametricBVP[{y'[x] == c x, y[1] == 1 && y[0] == 0}, y[x], x, c]

(*  {{y[x] -> x^2}}  *)

Guarantee: This has been thoroughly tested on the OP's single example and on no others. :) You're probably better off using @Sjoerd's, @Michael's, or @Okkes's approach, even though such approaches should be unnecessary. However, I think parametricBVP could give WRI a good idea how to extend DSolve. The parameters to be eliminated could be specified with an option. In the above, I followed the syntax of ParametricNDSolve.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.