# Solving a differential equation with a logarithm [closed]

I want to solve the equation

Eqn = Ns - (Sh*theta[x]*Log[1 + tr*theta[x]] -
1/(theta[x] + (tr - 1)^(-1))*D[theta[x], {x, 2}]) == 0;


and plot their solution x versus Ns I have written code But it does not work.

sol[Sh_] :=
Table[{Ns,
theta[0] /.
First@NDSolve[{Ns - (Sh*theta[x]*Ln[1 + tr*theta[x]] -
1/(theta[x] + (tr - 1)^(-1))*D[theta[x], {x, 2}]) == 0,
theta[1] == 1, theta'[0] == -0.250}, theta, {x, 0, 1}]}, {Ns,
0, 5, 0.1}];

pt1 = ListLinePlot[{Evaluate[sol[0]], Evaluate[sol[8]],
Evaluate[sol[10]], Evaluate[sol[80]], Evaluate[sol[50]],
Evaluate[sol[23]]},
PlotStyle -> {Red, Green, Blue, Black, Cyan, Pink},
PlotLegends ->  Frame -> True,
FrameLabel -> {X, Ns}, LabelStyle -> Directive[Red, Bold],Axes -> False]


• Is Ln[1 + Tr*theta[x]]  a function? Then you should show it to us. If you mean product, you should write Ln (1 + Tr*theta[x])  and give Ln a value. – Akku14 Oct 17 at 8:06
• If Ln is meant to be the natural logarithm, you should code Log. Also Tr is a Mathematica function that takes the trace of a matrix, or of a tensor. It is common practice to use variable names that begin with a lowercase letter, to avoid conflicts with Mathematica keywords. – LouisB Oct 17 at 8:18
• The parameter  Tr is undefined! – Ulrich Neumann Oct 17 at 12:16

Try ParametricNDSolveValue

θ =
ParametricNDSolveValue[
{Ns - (Sh*theta[x]*Log[1 + Tr*theta[x]] -1/(theta[x] +
(Tr - 1)^(-1))*D[theta[x], {x, 2}]) == 0,
theta[1] == 1, theta'[0] == -0.250},
theta, {x, 0, 1}, {Ns, Sh, Tr}]


This gives the solution θ depending on the parameters Ns, Sh, Tr Plot the solution for examplary parameters Ns==1, Sh==.5, Tr==-.1

Plot[θ[1, .5, -.1][x], {x, 0, 1}]


Result for variing Ns (x==0) :

Table[θ[ns, .5, -.1][0], {ns, 0, 5, 1}]
(*{1.26001, 1.50832, 2.18313, -0.521793, 0.421456, 0.621914}*)

• the answer is useful. I want to plot the solution x versus Ns please help me how to do it – zia ud din Oct 17 at 17:07
• Try Plot[θ[ns, .5, -.1][0], {ns, 0, 5}] or ListPlot[Table[θ[ns, .5, -.1][0], {ns, 0, 5, 1}]] – Ulrich Neumann Oct 18 at 8:46