I have a big function that I have to maximize, so I have to evaluate some equation with thousands of different values of the parameter. But the FindMaximum returns me many errors. I have traced the cause down to a differential equation that is part of the calculation. This differential equation has to be solved as function of the parameter (called "sup" in this case) and even though it is a seemingly "easy" function and I don't need a very high precision, in many points it does not converge and reaches the maximum number of steps. The following is a simplified sample code to view the problem with a Manipulate: as you slide the cursor with the Sup variable the NDsolve produces errors.
Manipulate[
Module[{pend, tmax}, tmax = 30;
pend = NDSolve[{1.1089 α''[t] + 1.2936 Sin[α[t]] +
210*sup*
(0.33 Sin[α[t]] + (
0.33^2 Cos[α[t]] Sin[α[t]])/Sqrt[
1 - 0.33^2 Sin[α[t]]^2]) *
UnitStep[Sin[α[t] + Pi*UnitStep[-α'[t]]]] ==
0, α[0] == -Pi/3, α'[0] == 0}, α, {t, 0,
tmax}, MaxSteps -> 10^5, PrecisionGoal -> 8,
AccuracyGoal -> acc];
Plot[α[x] /. pend, {x, 0, tmax}]], {{sup, 0.01, "Sup"}, 0.01,
0.1, Appearance -> "Labeled"}, {{acc, 8, "Acc"}, 6, 10, 1,
Appearance -> "Labeled"}, Bookmarks -> {
"Error1" :> {sup = 0.0577, acc = 7},
"Error2" :> {sup = 0.0413, acc = 8},
"Error3" :> {sup = 0.0351, acc = 6}}]
I have tried with increasing the MaxSteps and reducing the AccuracyGoal/PrecisionGoal, but it seems that there are always points in which the NDSolve does not return a good solution. And thus I cannot execute the FindMaximum to maximize my function.
Any hint on how to avoid this kind of problem and get NDSolve to return a correct result? Is there a way to trace down why NDSolve has this problems of convergence with this function?
Thanks for any help,
JBB
PD: Code update to define tmax. In the manipulate Bookmarks I have placed some examples of errors.