# Solving a differential equation with mixed conditions using DSolve

I want to solve a differential equation $$\frac{d}{dx}\left(k_0 \left(\frac{T(x)}{T_0}\right)^n \frac{dT(x)}{dx}\right)=0,$$ with boundary conditions: $T(l)=T_0$, $\;T'(0)=-\frac{q_0}{k_0 T(0)^n}\;$ using DSolve, but I cannot get a solution. Can anyone help me?

• Your equation appears to be missing a bracket, (. Also, did you mean to write $T[x]$ instead of $T[l]$ in the boundary conditions? – shrx Dec 4 '13 at 21:13
• T is a function of x – user10947 Dec 4 '13 at 21:19
• d/dx[k0 (T/T0)^n dT/dx]=0 Boundary Condition is: at x=L, T=T0, at x=0, dT/dx= -q0/(k0 T(0)) – user10947 Dec 4 '13 at 21:21
• Funny that k0 does not play any role in the equation. You can cancel it out. – Peltio Dec 4 '13 at 21:27
• It showed in boundary conditions – user10947 Dec 4 '13 at 23:36

I would just notice that

$$\frac{d}{dx}(k_0 (\frac{T[x]}{T_0})^n \frac{dT[x]}{dx})=k_0/T_0^n \frac{1}{n+1}\frac{d}{d x^2} T[x]^{n+1}$$

and therefore I'd solve it as below :

(* Solve the differential equation and rename the integration constants *)
aux = (Tnp1 /. First@DSolve[k0/T0^n 1/(n+1) Derivative[Tnp1][x] == 0, Tnp1, x])
/. {C -> a, C -> b}

(* The solution with the constants to be fixed *)
solT = Function[x, (aux[x])^(1/(n + 1)) ]

(* Solve for the constants *)
const = FullSimplify[Solve[{solT[l] == T0, solT' solT^n == -q0/k0} , {a, b}],
Assumptions -> {n > 0}]
(* {{a -> (l (1 + n) q0)/k0 + T0^(1 + n), b -> -(((1 + n) q0)/k0)}} *)

(* put everything together *)
finalT[x_] = solT[x] /. First[const]
(* ((l (1 + n) q0)/k0 + T0^(1 + n) - ((1 + n) q0 x)/k0)^(1/(1 + n)) *)


Check :

Block[{n = 6},
{finalT[l], finalT' finalT^n}
]
(* {(T0^7)^(1/7), -(q0/k0)} *)

• @Nasser I'm just saying $\frac{d}{dx}T^{n+1} = (n+1)\ T^n\ \frac{d}{dx} T$. – b.gates.you.know.what Dec 5 '13 at 9:09
• @Artes I don't do terrible calculus on purpose. Please help us correcting our mistakes. – b.gates.you.know.what Dec 5 '13 at 9:13
• Here it is again: $\frac{d}{dx}\left( T^{n}\frac{dT}{dx}\right) =\frac{dT^{n}}{dx}\frac {dT}{dx}+T^{n}\frac{d^{2}T}{dx^{2}}=nT^{n-1}\frac{dT}{dx}\frac{dT}{dx} +T^{n}\frac{d^{2}T}{dx^{2}}=nT^{n-1}\left( \frac{dT}{dx}\right) ^{2} +T^{n}\frac{d^{2}T}{dx^{2}}$ – Nasser Dec 5 '13 at 9:21
• @Nasser What you do is correct but the simplification happens if you work backwards; you don't want to expand the derivative but rather use that $T^n \frac{d}{dx T} = \frac{1}{n+1} \frac{d}{d x}T^{n+1}$. This way the equation is simply $\frac{d}{dx^2} T^{n+1} = 0$. – b.gates.you.know.what Dec 5 '13 at 9:26

The problem is that your BC's are not linear. So Mathematica can't solve for C and C. May be if you use numerical values for some of the parameters, then they can be solved.

You can solve leaving the IC's out and get a solution with C and C later as follows

ClearAll[x, n, k0, T, q, len]
f[x_, n_] := k0  (T[x]/T0)^n T'[x]
T[x_] = T[x] /. Last@DSolve[D[f[x, n], x] == 0, T[x], x] Plot[T[x] /. {len -> 1, C -> 2, C -> 3, n -> 3}, {x, 0, 10}] bc1 = T[len] == T0 c2 = C /. First@Solve[bc1, C] bc2 = (T'[x] /. x -> 0) == - q0/(k0 (T /. x -> 0)^n) eqForC1 = bc2 /. C -> c2 And now just need to solve for C and then can find C and hence the solution. But to solve for C, need numerical solution as it is non-linear. Hence need numerical values for the parameters in the equation for C.

• The problem is that the solution from last DSolve is not like the what I had now. The result should be in the form T[x]=(c1*x+c2)^(n+1). – user10947 Dec 5 '13 at 5:47

To complete my first comment (Hey, I've been scolded by the system because it was too long) I suggest to use a shooting (or balistic) method: instead of using mixed boundary conditions (at x=0 and x=l), specify the values of T and T' at the same extreme of the x interval, leaving the one that did not appear in the original problem as a parameter a to be determined. (I am not sure if To and T should be the same, so you might want to adapt the code accordingly)

eq = Expand[D[ko (T[x]/To)^n  T'[x], x]] == 0

sol = DSolve[Flatten[{eq, T == a, T' == -q0/(ko a^n)}], T[x], x];
f[x_, a_] = T[x] /. Last[sol]


This will give you a hint of the value of a for generic integer n (I am using First here to return only one root per equation; perhaps a function capable of returning a real solution would be better):

Table[{k, a /. First[Solve[f[l, a] - To == 0/. n -> k, a]]}, {k, 0, 6}]


If you are confident you have found a closed form solution, you could try it into your f[x,a], that is T[x] with initial condition T==a. For example, (EDIT, earlier I had used n instead of n+1)

t[x_] = f[x, a] /. a -> (To^(n+1) + (n+1) l q0/ko)^(1/(n+1)) // PowerExpand // Simplify


I have implicitly assumed that n is an integer and the constants are all real. It is usually at this point that I discover I have used an equation different from the one of the actual problem. :-) Still I hope this "extended comment" will point you in the right direction.

newer EDIT: this solution is remarkably similar to that found by b.gatessucks. As a matter of fact, if we bring the premultiplying constant inside the big bracket, we get the same solution. We can verify that it satisfies the differential equation

D[ko (t[x]/To)^n  t'[x], x]==0 // FullSimplify
(* True *)


and the condition at L

t[l] == To // Simplify // PowerExpand
(* True *)


And it also checks the condition on the derivative

t' t^n // Simplify // PowerExpand
(* -q0/ko *)


(In my previous edits I was using To instead of T as I should have done). Double check by specifying a value for n:

Table[t' + q0/(ko t^n) , {n, 0, 7}] // Simplify // PowerExpand
(* {0,0,0,0,0,0,0} *)


Well, it appears that the shooting method works well, after all. It only needs someone less clumsy to manage it.

older EDIT: I wrote the part about using the wrong equation in mocking but it might very well be true. I am a bit confused by the role of To, since I tend to assume it is the value at 0. Results can be more complicated without the simplification given by putting ana in the condition for T'.

• you have a mistake here, the boundary condition is T[l]==a instead of T==a – user10947 Dec 5 '13 at 5:45
• The idea of the shooting method is to use a parametric initial condition a, to be determined by compliance with the boundary condition it is replacing. Your boundary condition at l is imposed by f[l,a]==To. But I might have messed up To with T. – Peltio Dec 5 '13 at 5:53