I think it would be better to use this simple code to explain my questions:
Clear["Global`*"]
int[a_?NumericQ, b_?NumericQ] :=
NIntegrate[Sin[y1[t] y2[t] r]/r, {r, a, b}];
(* int[a_, b_] := NIntegrate[Sin[y1[t] y2[t] r]/r, {r, a, b}];*)
(* This works, but gives some warnings. *)
odes = {y1'[t] == y2[t] y3[t],
y2'[t] == -y1[t] y3[t] + int[y2[t], y3[t]],
y3'[t] == -0.51 y1[t] y2[t] t, y1[0] == 0, y2[0] == 1, y3[0] == 2};
sol = NDSolve[odes, {y1, y2, y3}, {t, 0, 12}];
Plot[{y1[t], y2[t], y3[t]} /. sol // Evaluate, {t, 0, 12}]
The above code doesn't work, and gives the "NIntegrate::inumr:
errors:
"The integrand Sin[r\y1[t]\y2[t]]/r has evaluated to non-numerical values for all sampling points in the region with boundaries {{1.,2.}}."
Two question:
(1) I want all the functions in my odes are purely numerically defined (i.e., use _?Numeric@
), why mathematica doesn't allow this. mathematica seems treat all ode functions (y1,y2,y3 in my code) analytically, so is it possible to use a numerically defined function (int
in my code) that depend on ode functions in NDSolve?
(2) If I delete _?Numeric@
(which is not my favored solution), the code posted works, but gives warnings, how can I avoid these warnings.
Thanks! :)
a
andb
do receive numerical values, buty1
andy2
do not... $\endgroup$int
in my above code) ? $\endgroup$NIntegrate
withIntegrate
fixed that specific problem. But then you use symbolic again. I don't think this can be done completely numerical. $\endgroup$NDSolve
? $\endgroup$