One way to diagnose this is to add something like Print[sol]
in the With
. It will show quite clearly that the substitution did not take place. Why is that? Because it is a literal substitution, and the variables g
et al do not appear literally in the body of the With
statement.
Here is a way to proceed. Define the ODE system inside the With
statement.
With[{g = 9.81, \[Alpha] = 20, l = 1, L = 1, A = 1, w = 50},
eq1 = \[Theta]''[t] - A w^2 l Cos[\[Theta][t]] Sin[w t] -
l g Sin[\[Theta][
t]] + (l \[Phi]'[t]^2 Sin[\[Theta][t] - \[Phi][t]] +
l \[Phi]''[t] Cos[\[Theta][t] - \[Phi][t]])/\[Alpha] == 0;
eq2 = \[Phi]''[
t] - (g Sin[\[Phi][t]] + A w^2 Cos[\[Phi][t]] Sin[w t] +
l \[Theta]'[t] Sin[\[Theta][t] - \[Phi][t]] -
l \[Theta]''[t] Cos[\[Theta][t] - \[Phi][t]])/L == 0;
sol = NDSolve[
{eq1, eq2, \[Theta]'[0.1] == 5, \[Phi]'[0.1] == 1, \[Theta][0] ==
0, \[Phi][0] == 0}, {\[Theta][t], \[Phi][t]}, {t, 10}];
sol]
This runs for me without error and produces a solution.
--- edit ---
Better way: force evalution inside With
so the substitution of variables can occur.
With[{g = 9.81, \[Alpha] = 20, l = 1, L = 1, A = 1, w = 50},
sol = Evaluate[
NDSolve[{eq1, eq2, \[Theta]'[0.1] == 5, \[Phi]'[0.1] == 1, \[Theta][0] == 0, \[Phi][0] == 0}, {\[Theta][t], \[Phi][t]}, {t, 10}]];
sol]
--- end edit ---