i have a task to find a event, to achieve this i think need to integrate until a constant function suddenly breaks the equilibrium and give a sharp peak. I think that EventLocator should work, thus tried the proposals from How to use NDSolve to track equilibrium?, with a threshold, but the numerical calculator is still complaining that the value before and after the step are not real numbers, but this would not be the case in theory, the code:
psi=Pi;
For[i=1,i<141,i++,w[i]=1/2];
fext=1;
k = 35.529;
ci = Table[y[i][0] == RandomReal[{-Pi, Pi}], {i, 1, 141}];
AppendTo[ci,y[0][0] == y[141][0] - psi];
lckm = {y[0]'[t] == fext, y[141]'[t] == fext,Table[y[i]'[t] ==
w[i] +
k (Sin[y[i + 1][t] - y[i][t]] +
Sin[y[i - 1][t] - y[i][t]]), {i, 1,
140}]};
sol = NDSolve[{lckm, ci},
Table[y[i], {i, 0, 141}], {t, 0.0, 800.0},
WorkingPrecision -> 30, AccuracyGoal -> 15, PrecisionGoal -> 15,
MaxSteps -> Infinity];
v1 = y[140][t] /. sol[[1]];
v2 = y[141][t] /. sol[[1]];
norm = Sin[v1 - v2] /. t -> 800;
k = 35.526;
ci = Table[
y[i][0] ==
Part[{y[i][t] /. sol} /. t -> 800.0, 1], {i, 1, 141}];
AppendTo[ci, y[0][0] == y[141][0] - psi];
lckm = {y[0]'[t] == fext, y[141]'[t] == fext,Table[y[i]'[t] ==
w[i] +
k (Sin[y[i + 1][t] - y[i][t]] +
Sin[y[i - 1][t] - y[i][t]]),{i, 1,
140}]};
sol = NDSolve[{lckm, ci},
Table[y[i], {i, 0, 141}], {t, 0.0, 800.0},
Method -> {"EventLocator",
"Event" ->
Boole[Abs[
Sin[y[140][t] - y[141][t]]/norm - 1] >
1/10], "EventAction" -> Print["t:", t]},
WorkingPrecision -> 30, AccuracyGoal -> 15, PrecisionGoal -> 15,
MaxSteps -> Infinity]
All the constant have a value well ascertained value, including norm that is a normalization responsable for the deviation detect. The answer to this, in mathematica 7, is:
NDSolve::precw: The precision of the differential equation ({((y[0])^\[Prime])[t]==1,((y[141])^\[Prime])[t]==1,((y[1])^\[Prime])[t]==1/2+66.439 (Sin[Subscript[\[Null], <<2>>][<<1>>]+Times[<<2>>]]-Sin[Plus[<<2>>]]),<<6>>,((y[8])^\[Prime])[t]==1/2+66.439 (Sin[\[Null], <<2>>][<<1>>]+Times[<<2>>]]-Sin[Plus[<<2>>]]),<<274>>}) is less than WorkingPrecision (30.`). >>
NDSolve::evre: The value of the event function at t = 2.79284074034703538067228005241`30.*^-10 was not a real number. The event will be ignored in steps where it does not evaluate to real numbers at both ends. >>
Please note that this logic is set to work, i.e. this error is not dependent in the value of norm in the sense that it needs it to detect the deviation. The point is: why Mathematica is outputing an error saying that something is not a real number ? where is the thing that is not a real number ?
Iam sorry if the example is too extense, i think that the problem poses it in this form or iam too newbie in mathematica and dont know rewrite.
Does anyone has any suggestion in order to circumvent it ?
Thank you !!!
fext,k,ciandnormare missing). Chances that someone sees the problem right away are small, being able to run the code will help a lot. I also think it would maybe make sense to rewrite the code without theSubscriptand instead usey[141][t]which will make it easiert to read the code here. It is also common practice to separate output from input in one way or another. – Albert Retey May 08 '12 at 08:00