I am new to this community and also to Mathematica. I am trying to solve a set of coupled first order differential equations related to the shape of a liquid drop. The code is as follows :

file = OpenWrite["profile.dat", FormatType -> OutputForm]
a = 0.29; b = 136250000; zmin = 2.022; smax = 7.330;
Eq1 = r'[s] == cos[θ[s]]
Eq2 = z'[s] == sin[θ[s]]
Eq3 = θ'[s] == (2*a) - (b*z[s]) - (sin[θ[s]]/r[s])
sol = NDSolve[{Eq1, Eq2, Eq3, r[0] == 0,z[0] == zmin, θ[0] == 0}, {r, z, θ}, {s, 0, smax}]
Write[file, r[s], " ", z[s]]

However, while I am evaluating the code I am getting two errors constantly as mentioned below;


Power::infy: "Infinite expression 1/0. encountered.


NDSolve::ndnum: Encountered non-numerical value for a derivative at s == 0;

Kindly help me to resolve this. Also, I am unable to plot or write the value of r[x] and z[x] for each value of s.

  • 4
    $\begingroup$ For starters, The cosine and sine functions in mma are Cos and Sin. $\endgroup$ – MarcoB Jul 26 '18 at 13:05
  • $\begingroup$ You have a singularity boundary condition with r[0]=0 which is what is being flagged via the error: ndnum. Why not try using NDSolveValue and Export to export data. Your code does run with these short modifications and setting r[0]=0.0000001 instead of 0. But then I run into MaxSteps issue. $\endgroup$ – dearN Jul 28 '18 at 23:52

Use Cos[] and Sin[] and excluded the singularity in numerical calculations.

a = 0.29; b = 136250000; zmin = 2.022; smax = 2.99; s0 = 0.;
Eq = {r'[s] == Cos[θ[s]], 
   z'[s] == Sin[θ[s]], θ'[s] == 
    2*a - b*z[s] - (Sin[θ[s]]/r[s])};
ic = {r[s0] == 10^-7, z[s0] == zmin, θ[s0] == 0};
sol = NDSolve[{Eq, ic}, {r, z, θ}, {s, s0, smax}];
{Plot[Evaluate[r[s] /. sol], {s, s0, smax}, PlotRange -> All, 
  AxesLabel -> {"s", "r"}], 
 Plot[Evaluate[z[s] /. sol], {s, s0, smax}, PlotRange -> All, 
  AxesLabel -> {"s", "z"}], 
 Plot[Evaluate[θ[s] /. sol], {s, s0, smax}, PlotRange -> All, 
  AxesLabel -> {"s", "θ"}]}


  • 4
    $\begingroup$ I think it would be useful to OP, who mentions their inexperience, if you could comment on what was wrong with their code and what you changed to make it work. $\endgroup$ – MarcoB Jul 26 '18 at 13:06
  • $\begingroup$ there is nothing to comment on, just obvious errors with the use of functions Cos[], Sin[] and one singularity, which should be excluded in numerical calculations. $\endgroup$ – Alex Trounev Jul 26 '18 at 13:51
  • $\begingroup$ Hello Alex and MarcoB, thanks a lot. I was stuck with this errors since last two days. It helped me a lot. Can you kindly tell me how I will be able to store the values of r,z, and theta for each value of s in a single .dat file? $\endgroup$ – Mr . X Jul 26 '18 at 14:45
  • $\begingroup$ @Mr.X Please see my comment in your original question about Export. $\endgroup$ – dearN Jul 29 '18 at 0:06

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