3
$\begingroup$

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]

please help me

$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – Akku14 Oct 17 at 8:06
  • 4
    $\begingroup$ 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. $\endgroup$ – LouisB Oct 17 at 8:18
  • 1
    $\begingroup$ The parameter ` Tr` is undefined! $\endgroup$ – Ulrich Neumann Oct 17 at 12:16
5
$\begingroup$

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}]

enter image description here

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}*)    
| improve this answer | |
$\endgroup$
  • $\begingroup$ the answer is useful. I want to plot the solution x versus Ns please help me how to do it $\endgroup$ – zia ud din Oct 17 at 17:07
  • $\begingroup$ Try Plot[θ[ns, .5, -.1][0], {ns, 0, 5}] or ListPlot[Table[θ[ns, .5, -.1][0], {ns, 0, 5, 1}]] $\endgroup$ – Ulrich Neumann Oct 18 at 8:46

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