# NDSolve in exact points - nonlinear equation (Degrees and Radians confusion)

I found solutions of two nonlinear equations, but I have three small questions.

First I am in confusion because of initial value. The system is mechanical and unknown ϕ is an angle, which I set to be in position of 90 degrees (Pi/2). Is it correct setting in equation initial position?

Second question: I am looking for discrete points of an angle values here

 ϕ = 90 Degree (Pi/2 Radians)
ϕ = 80 Degree (1.396 Radians)
ϕ = 70 Degree (1.221 Radians)
ϕ = 30 Degree (0.523 Radians)
ϕ = 20 Degree (0.349 Radians)
ϕ = 10 Degree (0.174 Radians)
ϕ = 0 Degree (0 Radians)


Numerical solutions of these values down and in which time

 {z[t], z'[t], ϕ'[t], ϕ''[t], z''[t], t}


I solved the system and obtained solutions, but I don't know how to extract these values from the diagrams.

Third question: I am looking for to obtain FindMinimum[zsol[t],t] and FindMaximum[zsol[t],t] but Mathematica gives value which is not extrema because I can see from the diagram that it is not extrema.

 c1 = 7.5*10^3;
m = 10;
l = 1;
M = 75;
g = 9.81;

{zsol, ϕsol} =
NDSolveValue[
{z''[t] - (M l)/(m + M) ϕ''[t] Sin[ϕ[t]] - (M l)/(m + M)
(ϕ'[t])^2 Cos[ϕ[t]] + c1/(m + M) z[t] == 0,
ϕ''[t] - 1/l z''[t] Sin[ϕ[t]] + g/l Sin[ϕ[t]] == 0,
z[0] == -((M g)/c1), z'[0] == 0, ϕ[0] == Pi /2, ϕ'[0] == 0},
{ϕ, z}, {t, 0, 15}]

Plot[{zsol[t], ϕsol[t]}, {t, 0, 5}, PlotStyle -> {Red, Blue}]
Plot[{zsol[t]}, {t, 0, 5}, PlotStyle -> {Red}]
Plot[{ϕsol[t]}, {t, 0, 5}, PlotStyle -> {Blue}]


Solutions

• small note i believe you've reversed {zsol, ϕsol} compared to the order you requested them. – george2079 Mar 23 '14 at 16:00
• take a look at the answer here mathematica.stackexchange.com/questions/44334/… using WhenEvent – george2079 Mar 23 '14 at 16:51
• As your interpolating functions are only valid in the t-range where you solved the equation you should include that as a constraint. I would also suggest to use NMinimize/NMaximize if you search a global min/max of a numeric function, they seem to work well for your problem:NMaximize[{zsol[t], 0 <= t <= 15}, t] – Albert Retey Mar 24 '14 at 9:18

First, it is correct.

Second

p1 = Plot[{zsol[t]}, {t, 0, 5}, PlotStyle -> {Red}, PlotPoints -> 500];
error = 0.01;
select[ϕ_] :=
Select[First@Cases[p1, Line[x_] -> x, Infinity], Abs[#[[2]] - ϕ] < error &]
select[0.174]
Show[p1, ListPlot[%, PlotStyle -> {Red, PointSize[0.02]}]]


If you need more precision，increase PlotPoints and decrease error.

The enhanced version

Clear["Global*"]
ϕpos = {0, 0.174, 0.349, 0.523, 1.221, 1.396, 1.571};
c1 = 7.5*10^3; m = 10; l = 1; M = 75; g = 9.81;
sol = First@
NDSolve[{z''[t] - (M l)/(m + M) ϕ''[
t] Sin[ϕ[t]] - (M l)/(m + M) (ϕ'[t])^2 Cos[ϕ[t]] + c1/(m + M) z[t] ==
0, ϕ''[t] - 1/l z''[t] Sin[ϕ[t]] + g/l Sin[ϕ[t]] == 0, z[0] == -((M g)/c1),
z'[0] == 0, ϕ[0] == Pi/2, ϕ'[0] == 0}, {ϕ, z}, {t,0, 15}];
error = 0.005; step = 0.002;
tpos[ϕ0_] :=
Mean /@ Gather[Select[{#, ϕ[#] /. sol} & /@ Range[0, 5, step],
Abs[#[[2]] - ϕ0] < error &][[All, 1]], Abs[#1 - #2] < error &]
AllData[tlist_] := Table[{t, ϕ[t], z[t], z'[t], ϕ'[t], ϕ''[t], z''[t]}
/. sol, {t, tlist}]
grid[ϕ_] :=
Grid@Join[{{"t", "ϕ", "z", "z'", "ϕ'", "ϕ''", "z''"}},AllData[tpos[ϕ]]]
trans[func_] :=
Which[func == "ϕ", {1, 2}, func == "z", {1, 3},
func == "z'", {1, 4}, func == "ϕ'", {1, 5},
func == "ϕ''", {1, 6}, func == "z''", {1, 7}]
Manipulate[
Column[{grid[ϕ], Show[Plot[Evaluate[ToExpression[func][t] /. sol], {t, 0, 5},
ImageSize -> 400], ListPlot[AllData[tpos[ϕ]][[All, trans[func]]],
PlotStyle -> {Red, PointSize[0.02]}]]}], {ϕ, ϕpos}, {func, {"ϕ",
"z", "z'", "ϕ'", "ϕ''", "z''"}}, ControlType -> RadioButton]

zsol[t_] := z[t] /. sol;
max = {#2[[1, 2]], #1} & @@ NMaximize[{zsol[t], 0 < t < 5}, t]
min = {#2[[1, 2]], #1} & @@ NMinimize[{zsol[t], 0 < t < 5}, t]
Show[Plot[zsol[t], {t, 0, 5}], ListPlot[{max, min}, PlotStyle -> {Red, PointSize[0.02]}]]
`

• I need position of z, velocity z', angular velocity ϕ' and angular acceleration ϕ'' for various ϕ which I choose and for which t. It should be table of 6x7 of data? {z[t], z'[t], ϕ'[t], ϕ''[t], z''[t], t} – Pipe Mar 23 '14 at 16:08
• just for first cycle – Pipe Mar 23 '14 at 16:09
• you need learn my code and rewrite it for you need. – Apple Mar 23 '14 at 16:12
• I think I can handle, thank you very much – Pipe Mar 23 '14 at 16:19
• I used FindMaximum[zsol[t], t] on the segment but doesn't work? I obtained value which is not maximum because I can see from the diagram – Pipe Mar 23 '14 at 17:32