# Why won't Graphics plot my point with coordinates depending on the solution of NDSolve?

ClearAll["Global*"]

L0 = 2;
\[Omega] = 4;
L[t_] = L0 + \[Delta] *Sin[\[Omega]*t + Pi];
x[t_] = L[t]*Cos[\[Alpha][t]];
y[t_] = L[t]*Sin[\[Alpha][t]];
T = m/2 * ((x'[t])^2 + (y'[t])^2);
U = -m*g*x[t];
Lagr = T - U;
Lgr = Simplify[Expand[Lagr]];
Eq1 = D[#1, #2] - D[D[#1, #3], t] & [Lgr, \[Alpha][t], \[Alpha]'[t]];
Eq2 = Solve[Eq1 == 0, \[Alpha]''[t]];
Equ = Eq1 /. g -> L0*\[CapitalOmega]^2 /. \[Delta] -> (\[CurlyEpsilon] * L0)/(\[CapitalOmega]^2);
\[Alpha]max = 1;
Lu[t_] = L[t] /. g -> L0*\[CapitalOmega]^2 /. \[Delta] -> (\[CurlyEpsilon] * L0)/(\[CapitalOmega]^2);

Equa = Equ /. \[CapitalOmega] ->  1 /.\[CurlyEpsilon] -> 0.05 /. m->1;

Lua[t_] = Lu[t] /. \[CapitalOmega] ->  1 /. \[CurlyEpsilon] -> 0.05 /. m->1;

sol = NDSolve[{Equa ==
0, \[Alpha][0] == 1, \[Alpha]'[0] == 0}, \[Alpha][
t], {t, -10, 10}, MaxSteps -> 100000];

a[t_] = \[Alpha][t]/.sol;

x1[t_] = Lua[t]*Cos[a[t]];

Show[Graphics[{Black, AbsolutePointSize[10],
Point[{x1[1],0}]}, Axes -> True],PlotRange->{{-10,10},{-10,10}}]


It must be a problem with the Point function here I guess.

Because if I instead want to plot the graph x1[t], i.e.

Plot[x1[t], {t, -10, 10}]


then it works.

Also, if I do

Show[Graphics[{Black, AbsolutePointSize[10],
Point[{0,0}]}, Axes -> True],PlotRange->{{-10,10},{-10,10}}]


It works and it shows me a black point at (0,0) (also, the Lua function works too without any problems, I can plot points which depend on the Lua function).

The problem only arises if I include x1[t] into it, then for some reasons the Graphics function (or Points function, I don't know which one here is the culprit) doesn't show me anything, it only shows me this:

EDIT

Even if I do

x1[1][[1]]


Then it still doesn't work if I try to animate it using Manipulate:

ClearAll["Global*"]

L0 = 2;
\[Omega] = 4;
L[t_] = L0 + \[Delta] *Sin[\[Omega]*t + Pi];
x[t_] = L[t]*Cos[\[Alpha][t]];
y[t_] = L[t]*Sin[\[Alpha][t]];
T = m/2 * ((x'[t])^2 + (y'[t])^2);
U = -m*g*x[t];
Lagr = T - U;
Lgr = Simplify[Expand[Lagr]];
Eq1 = D[#1, #2] - D[D[#1, #3], t] & [Lgr, \[Alpha][t], \[Alpha]'[t]];
Eq2 = Solve[Eq1 == 0, \[Alpha]''[t]];
Equ = Eq1 /. g -> L0*\[CapitalOmega]^2 /. \[Delta] -> (\[CurlyEpsilon] * L0)/(\[CapitalOmega]^2);
\[Alpha]max = 1;
Lu[t_] = L[t] /. g -> L0*\[CapitalOmega]^2 /. \[Delta] -> (\[CurlyEpsilon] * L0)/(\[CapitalOmega]^2);

Equa = Equ /. \[CapitalOmega] ->  1 /.\[CurlyEpsilon] -> 0.05 /. m->1;

Lua[t_] = Lu[t] /. \[CapitalOmega] ->  1 /. \[CurlyEpsilon] -> 0.05 /. m->1;

f[p_] := Module[{sol},sol = NDSolve[{Equa ==
0, \[Alpha][0] == 1, \[Alpha]'[0] == 0}, \[Alpha][
t], {t,p,p-1}, MaxSteps -> 100000];

a[t_] = \[Alpha][t]/.sol;

x1[t_] = Lua[t]*Cos[a[t]];
y1[t_] = Lua[t]*Sin[a[t]];

Show[Graphics[{Black, AbsolutePointSize[10],
Point[{x1[p][[1]],y1[p][[1]]}]}, Axes -> True],PlotRange->{{-10,10},{-10,10}}]];

Manipulate[f[p], {{p,0,"animate"},0,Infinity,ControlType->Trigger}]


Even if I do

x1[1][[1]], y1[1][[1]]


it still just shows an empty coordinate system. Whereas if I do

0, 0


Then it again shows me a black point at (0,0)

SECOND EDIT

Ok, it seems that I need to do a[t] := instead of =. But if I try to manipulate the parameters [CapitalOmega] and such in my animation, it still fails to work (it does show the black ball, but just as I start my animation, the ball vanishes and I still have a coordinate system with nothing in it)

Code:

ClearAll["Global*"]

L0 = 2;
\[Omega] = 4;
L[t_] = L0 + \[Delta] *Sin[\[Omega]*t + Pi];
x[t_] = L[t]*Cos[\[Alpha][t]];
y[t_] = L[t]*Sin[\[Alpha][t]];
T = m/2 * ((x'[t])^2 + (y'[t])^2);
U = -m*g*x[t];
Lagr = T - U;
Lgr = Simplify[Expand[Lagr]];
Eq1 = D[#1, #2] - D[D[#1, #3], t] & [Lgr, \[Alpha][t], \[Alpha]'[t]];
Eq2 = Solve[Eq1 == 0, \[Alpha]''[t]];
Equ = Eq1 /. g -> L0*\[CapitalOmega]^2 /. \[Delta] -> (\[CurlyEpsilon] * L0)/(\[CapitalOmega]^2);
Lu[t_] = L[t] /. g -> L0*\[CapitalOmega]^2 /. \[Delta] -> (\[CurlyEpsilon] * L0)/(\[CapitalOmega]^2);

Equa = Equ /. \[CapitalOmega] ->  1 /.\[CurlyEpsilon] -> 0.05 /. m->1;

Lua[t_] = Lu[t] /. \[CapitalOmega] ->  1 /. \[CurlyEpsilon] -> 0.05 /. m->1;

sol = NDSolve[{Equa == 0, \[Alpha][0] == 1, \[Alpha]'[0] == 0}, \[Alpha][ t], {t, -10, 10}, MaxSteps -> 100000];

a[t_] = \[Alpha][t]/.sol;

x1[t_] = Lua[t]*Cos[a[t]];
y1[t_] = Lua[t]*Sin[a[t]];

g[p_, \[Alpha]max_, \[CapitalOmega]_, \[CurlyEpsilon]_,m_] := Module[{sol1},sol1 =NDSolve[{Equ ==  0, \[Alpha][0] == \[Alpha]max, \[Alpha]'[0] == 0}, \[Alpha][
t], {t, p, p - 1}, MaxSteps -> 100000];Show[Graphics[{Black, AbsolutePointSize[10],
Point[{Lu[p]*Sin[sol1[p][[1]]],-Lu[p]*Cos[sol1[p][[1]]]   }]}, Axes -> True],PlotRange->{{-10,10},{-10,10}}]];

Show[Graphics[{Black, AbsolutePointSize[10],
Point[{x1[1][[1]],y1[1][[1]]}]}, Axes -> True],PlotRange->{{-10,10},{-10,10}}];

Manipulate[Show[Graphics[{Black, AbsolutePointSize[10],
Point[{y1[p][[1]],-x1[p][[1]]}]}, Axes -> True],PlotRange->{{-10,10},{-10,10}}], {{p, 0, "animation"}, 0, Infinity, ControlType -> Trigger}];

Manipulate[ g[p, \[Alpha]max, \[CapitalOmega], \[CurlyEpsilon], m], {{\[Alpha]max,  1}, 1, 10}, {{\[CapitalOmega], 1}, 1, 6.5}, {{\[CurlyEpsilon], 0.05}, 0.05, 0.5},{{m,1},1,10}, {{p, 0, "animation"},  0, Infinity, ControlType -> Trigger}]


The problem I have with is the last manipulate where the g is plotted

• Replace Module to Block or ( ) Nov 11, 2022 at 14:14
• @cvgmt It doesn't work Nov 11, 2022 at 14:15

• If you use Module,we can replace a[t_] = α[t] /. sol; to a[t_]: = α[t] /. sol;
ClearAll["Global*"];
L0 = 2;
ω = 4;
L[t_] = L0 + δ*Sin[ω*t + Pi];
x[t_] = L[t]*Cos[α[t]];
y[t_] = L[t]*Sin[α[t]];
T = m/2*((x'[t])^2 + (y'[t])^2);
U = -m*g*x[t];
Lagr = T - U;
Lgr = Simplify[Expand[Lagr]];
Eq1 = D[#1, #2] - D[D[#1, #3], t] &[Lgr, α[t], α'[t]];
Eq2 = Solve[Eq1 == 0, α''[t]];
Equ = Eq1 /.
g -> L0*Ω^2 /. δ -> (ε*
L0)/(Ω^2);
αmax = 1;
Lu[t_] =
L[t] /. g ->
L0*Ω^2 /. δ -> (ε*
L0)/(Ω^2);
Equa = Equ /. Ω -> 1 /. ε -> 0.05 /.
m -> 1;
Lua[t_] =
Lu[t] /. Ω -> 1 /. ε -> 0.05 /. m -> 1;
f[p_] :=
Module[{sol},
sol = NDSolve[{Equa == 0, α[0] == 1, α'[0] ==
0}, α[t], {t, p, p - 1}, MaxSteps -> 100000];
a[t_] := α[t] /. sol;
x1[t_] = Lua[t]*Cos[a[t]];
y1[t_] = Lua[t]*Sin[a[t]];
Show[Graphics[{Black, AbsolutePointSize[10],
Point[{x1[p][[1]], y1[p][[1]]}]}, Axes -> True],
PlotRange -> {{-10, 10}, {-10, 10}}]];
Manipulate[
f[p], {{p, 0, "animate"}, 0, Infinity, ControlType -> Trigger}]

• If we keep on use a[t_] = α[t] /. sol;, We can replace Module to ( ) or Block.
ClearAll["Global*"];
L0 = 2;
ω = 4;
L[t_] = L0 + δ*Sin[ω*t + Pi];
x[t_] = L[t]*Cos[α[t]];
y[t_] = L[t]*Sin[α[t]];
T = m/2*((x'[t])^2 + (y'[t])^2);
U = -m*g*x[t];
Lagr = T - U;
Lgr = Simplify[Expand[Lagr]];
Eq1 = D[#1, #2] - D[D[#1, #3], t] &[Lgr, α[t], α'[t]];
Eq2 = Solve[Eq1 == 0, α''[t]];
Equ = Eq1 /.
g -> L0*Ω^2 /. δ -> (ε*
L0)/(Ω^2);
αmax = 1;
Lu[t_] =
L[t] /. g ->
L0*Ω^2 /. δ -> (ε*
L0)/(Ω^2);
Equa = Equ /. Ω -> 1 /. ε -> 0.05 /.
m -> 1;
Lua[t_] =
Lu[t] /. Ω -> 1 /. ε -> 0.05 /. m -> 1;
f[p_] := (sol =
NDSolve[{Equa == 0, α[0] == 1, α'[0] ==
0}, α[t], {t, p, p - 1}, MaxSteps -> 100000];
a[t_] := α[t] /. sol;
x1[t_] = Lua[t]*Cos[a[t]];
y1[t_] = Lua[t]*Sin[a[t]];
Show[Graphics[{Black, AbsolutePointSize[10],
Point[{x1[p][[1]], y1[p][[1]]}]}, Axes -> True],
PlotRange -> {{-10, 10}, {-10, 10}}]);
Manipulate[
f[p], {{p, 0, "animate"}, 0, Infinity, ControlType -> Trigger}]

• Thanks, but it still doesn't work if I want to plot my function where CapitalOmega etc are parameters you can change in the animation (I've edited the question so you can take a look at the code). Nov 11, 2022 at 14:43
• Or use NDSolveValue. Nov 11, 2022 at 16:13

You have a syntax error. Look at what x1[1] returns::

x1[1]
(* {1.71046} *)


This is a list, not a number. And you get:

Point[{{1.71046},0}]


This is wrong. Therefore, what you must write is:

Show[Graphics[{Black, AbsolutePointSize[10], Point[{x1[1][[1]], 0}]},
Axes -> True], PlotRange -> {{-10, 10}, {-10, 10}}]


a[t_] = \[Alpha][t] /. sol[[1]];
`