I want to solve this equation and get a 2-dimensional plot with N2 on X-axis and theta(1) on the Y-axis with x from 0 to 1 and N2 varies from 0 to 5

theta''[x] + theta'[x] - 
   (N2)^2*theta[x] +theta[x]^3 == 0, theta'[1] == 1, 
 theta[0] == 0

I am new to Mathematica.

  • 1
    $\begingroup$ This is not solving your complete problem, but it is showing you how to solve a similar problem. First do this sol=theta[x]/.DSolve[{theta''[x]+theta'[x]-(N2)^2*theta[x]==0, theta'[1]==1, theta[0]==0},theta[x],x] and then do this Plot[Table[sol,{x,0,1,1/8}],{N2,0,5}] and see what you get. Then look up DSolve and Plot and Table and /. in the help system and study the examples. Try to understand what each part of this is doing. Then make tiny changes and see what happens until you think you understand this. Including the theta[x]^3 term fails. Can you solve that? $\endgroup$ – Bill Jan 11 '19 at 20:38

The desired situation can be plotted like this but you need to make sure your equation and boundary conditions are correct.

sol = Table[{N2, theta[1] /. First@NDSolve[{theta''[x] + theta'[x] -(N2)^2*theta[x] 
+ theta[x]^3 == 0, theta'[1] == 1, theta[0] == 0}, theta, {x, 0, 1}]}, {N2, 0, 5, 0.5}];

ListLinePlot[sol, PlotRange -> All]

If you look for a numerical solution try ParametricNDSolveValue[] which gives a parameter dependent solution

sys = {theta''[x] + theta'[x] - (N2)^2*theta[x] + theta[x]^3 == 0,theta'[1] == 1, theta[0] == 0}
\[Theta] = ParametricNDSolveValue[sys, theta, {x, 0, 1}, {N2}]  

The solution can be accessed in the form \[Theta][2.5][x] (first bracket=parameter, second bracket x)

Plot[\[Theta][2.5][x], {x, 0, 1},AxesLabel -> {"x", "\[Theta]"}]

enter image description here

The plot you asked for gathers the different solutions inside Table

Plot[Table[\[Theta][n2][x], {n2, 0, 5, 1}] // Evaluate, {x, 0, 1}, AxesLabel -> {"x", "\[Theta]"}, PlotRange -> All]

enter image description here

That's it!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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