# NDsolve and Coupled first order ODE solving [closed]

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]]
Close[file]

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

1)

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

2)

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.

## closed as off-topic by MarcoB, Henrik Schumacher, Coolwater, m_goldberg, rhermansJul 29 '18 at 8:46

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – MarcoB, Henrik Schumacher, Coolwater, m_goldberg, rhermans
If this question can be reworded to fit the rules in the help center, please edit the question.

• For starters, The cosine and sine functions in mma are Cos and Sin. – MarcoB Jul 26 '18 at 13:05
• 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. – 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", "θ"}]}

• 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. – MarcoB Jul 26 '18 at 13:06
• 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. – Alex Trounev Jul 26 '18 at 13:51
• 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? – Mr . X Jul 26 '18 at 14:45
• @Mr.X Please see my comment in your original question about Export. – dearN Jul 29 '18 at 0:06